HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseVertex3D.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseVertex3D.cxx
3 //
11 #include "HarpoAnalyseVertex3D.h"
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 "TSystem.h"
33 
34 #include <cstdlib>
35 #include <cstring>
36 #include <cassert>
37 #include <fstream>
38 #include <iostream>
39 
40 ClassImp(HarpoAnalyseVertex3D);
41 
43  {
44  unsigned int nd; // number of detectors
46 
47  assert(hdr != NULL);
48  hdr->print();
49 
50  for (nd = 0; nd < gkNDetectors; nd++) {
51  // if (fEvt->isdataExist(nd)) {
52  HarpoDccMap *plane = fEvt->GetDccMap(nd);
53  if (plane != NULL )plane->print();
54  }
55  }
56 
58 {
59  // Bool_t drawEvent = kFALSE;
60  nEvents++;
61  //???????????????????????????????
62  if(!fEvt->GetRecoEvent()) return;
63 
64 
65  Double_t angle_open_sim = 0;
66  Double_t angle_omega_sim = 0;
67  // Double_t psim[2][3];
68  TVector3 possim = TVector3(0,0,0);
69  TVector3 pgammasim = TVector3(0,0,1);
70  TVector3 ppolasim = TVector3(0,1,0);
71  TVector3 pgamma = TVector3(0,0,1);
72  TVector3 ppola = TVector3(0,1,0);
73  TVector3 ppositron, pelectron;
74  Double_t epositron = -1.0, eelectron = -1.0;
75  if (gHDetSet->isExist(SIMDET)){
77  Int_t nIonTr = simEvt->GetNtracks();
78  for(Int_t i = 0; i<nIonTr; i++){
80  Int_t nPoints = tr->GetNpoints();
81  for(Int_t j = 0; j<nPoints; j++){
82  // TpcSimIonisationPoint* point = tr->GetPoint(j);
83  //hNeSim->Fill(point->GetNe());
84  }
85  }
86  TpcSimMCEvent* mcEvent = simEvt->GetMCEvent();
87  Int_t nMCtr = mcEvent->GetNtracks();
88  // if(nMCtr==2){
89  // Double_t norm[2] = {0,0};
90  Bool_t palready = kFALSE;
91  for(Int_t i = 0; i<nMCtr; i++){
92  TpcSimMCTrack* track = mcEvent->GetTrack(i);
93  Int_t pdgcode = track->GetPdgCode();
94  if(pdgcode == 11 && palready) pdgcode = -11;
95  switch(pdgcode){
96  case 22:
97  possim = track->GetOrigin();
98  pgammasim = track->GetP();
99  ppolasim = track->GetPola();
100  pgamma = track->GetP();
101  ppola = track->GetPola();
102  break;
103  case 11:
104  palready = kTRUE;
105  ppositron = track->GetP();
106  epositron = track->GetE();
107  break;
108  case -11:
109  pelectron = track->GetP();
110  eelectron = track->GetE();
111  break;
112  // default:
113  // psim[i][0] = track->GetPx();
114  // psim[i][1] = track->GetPy();
115  // psim[i][2] = track->GetPz();
116  // norm[i] = TMath::Sqrt(psim[i][0]*psim[i][0]+psim[i][1]*psim[i][1]+psim[i][2]*psim[i][2]);
117 
118  }
119  //hPsim->Fill(track->GetPx(),track->GetPy(),track->GetPz());
120  }
121  Double_t u1u2 = ppositron.Unit()*pelectron.Unit();
122 
123  angle_open_sim=acos(u1u2);
124 
125  TVector3 ppola2 = ppolasim.Cross(pgammasim.Unit());
126  TVector3 pPlus = TVector3(ppositron.Dot(pgammasim.Unit()),ppositron.Dot(ppolasim.Unit()),ppositron.Dot(ppola2.Unit())).Unit();
127  TVector3 pMinus = TVector3(pelectron.Dot(pgammasim.Unit()),pelectron.Dot(ppolasim.Unit()),pelectron.Dot(ppola2.Unit())).Unit();
128  angle_omega_sim = atan2((pPlus.Px()*pMinus.Py() - pMinus.Px()*pPlus.Py()),
129  (pPlus.Px()*pMinus.Pz() - pMinus.Px()*pPlus.Pz()));
130 
131  hOpenSim->Fill(angle_open_sim);
132  hOmegaSim->Fill(angle_omega_sim);
133  //}
134  }
135 
136 
137 
138 
139 
140  HarpoRecoEvent* reco = fEvt->GetRecoEvent();
141 
142  const Int_t kNdata = 41;
143  Double_t data[kNdata];
144  for(Int_t i = 0; i<kNdata; i++) data[i] = -1000;
145  for(Int_t i = 0; i<3; i++){
146  data[10+i] = ppositron[i];
147  data[13+i] = pelectron[i];
148  }
149  data[32] = epositron;
150  data[33] = eelectron;
151 
152  TVector3 psumsim = ppositron + pelectron;
153  data[23] = psumsim.Unit().x();
154  data[24] = psumsim.Unit().y();
155  data[25] = psumsim.Unit().z();
156 
157  Double_t xStart[2] = {-1,-1};
158  Double_t zStart[2] = {1000,1000};
159  TClonesArray* clArray = reco->GetClustersArray();
160  Int_t nCl = clArray->GetEntries();
161  for(Int_t iCl = 0; iCl<nCl; iCl++){
162  HarpoRecoClusters* cl = (HarpoRecoClusters*)clArray->At(iCl);
163  Int_t plane = cl->GetPlane();
164  if(cl->GetZ()<zStart[plane]){
165  xStart[plane] = cl->GetX();
166  zStart[plane] = cl->GetZ();
167  }
168  }
169 
170  if(gHDetSet->isExist(PMM2)){
171  Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
172  data[34] = anaEvt->GetTriggerType();
173  }
174 
175  Double_t fTstart = 90;
176  Double_t fTend = 430;
177  Double_t fThr = 1e4;
178  for(Int_t plane = 0; plane<2; plane++){
179  if (!gHDetSet->isExist(plane)) continue;
180  // Process RAW data
181  HarpoDccMap* m = fEvt->GetDccMap(plane);
182  if ( m == NULL ) continue;
183  // Int_t i2 = 0;
184  Double_t qTotIn = 0;
185  Double_t qTotBefore = 0;
186  Double_t qTotAfter = 0;
187  for(Int_t j=0;j<NCHAN;j++){ // Channels
188  for(Int_t i=0;i<NADC;i++){ //Time bins
189  Double_t q = m->GetData(j,i);
190  if(q<0) continue;
191  if(i< fTstart ) qTotBefore += q;
192  if( i >fTend) qTotAfter += q;
193  if(i>=fTstart && i<=fTend) qTotIn += q;
194  }
195  }
196  if(qTotBefore>fThr || qTotAfter>fThr)
197  data[34] = -2;
198  data[35] = qTotBefore;
199  data[36] = qTotAfter;
200  }
201 
202 
203 
204 
205 
206 
207  data[0] = xStart[XPLANE];
208  data[1] = xStart[YPLANE];
209  data[2] = 0.5*(zStart[XPLANE]+zStart[XPLANE]);
210  data[26] = xStart[XPLANE];
211  data[27] = xStart[YPLANE];
212  data[28] = 0.5*(zStart[XPLANE]+zStart[XPLANE]);
213  data[29] = possim.x();
214  data[30] = possim.y();
215  data[31] = possim.z();
216  data[5] = angle_omega_sim;
217  data[6] = angle_open_sim;
218  data[22] = -1;
219  fNtuple->Fill(data);
220 
221 
222  TClonesArray* vArray = reco->GetVertex3DArray();
223  Int_t nV = vArray->GetEntries();
224  for(Int_t iV = 0; iV<nV; iV++){
225  HarpoRecoVertex3D* vertex = (HarpoRecoVertex3D*)vArray->At(iV);
226 
227  TVector3 p1 = vertex->GetP1Vertex3D();
228  TVector3 p2 = vertex->GetP2Vertex3D();
229 
230  Double_t u1u2 = p1.Unit()*p2.Unit();
231  Double_t angle_open=acos(u1u2);
232 
233  TVector3 ppola2 = ppola.Cross(pgamma);
234  TVector3 pPlus = TVector3(p1.Dot(pgamma.Unit()),p1.Dot(ppola.Unit()),p1.Dot(ppola2.Unit()));
235  TVector3 pMinus = TVector3(p2.Dot(pgamma.Unit()),p2.Dot(ppola.Unit()),p2.Dot(ppola2.Unit()));
236  Double_t angle_omega = atan2((pPlus.Px()*pMinus.Py() - pMinus.Px()*pPlus.Py()),
237  (pPlus.Px()*pMinus.Pz() - pMinus.Px()*pPlus.Pz()));
238 
239  data[0] = vertex->GetXvertex3D();
240  data[1] = vertex->GetYvertex3D();
241  data[2] = vertex->GetZvertex3D();
242  data[3] = angle_omega;
243  data[4] = angle_open;
244  TVector3 psum = (p1 + p2).Unit();
245  data[7] = psum.x();
246  data[8] = psum.y();
247  data[9] = psum.z();
248 
249  Double_t d1[2] = {0,0};
250  Double_t d2[2] = {0,0};
251  d1[0] = (ppositron - p1).Mag();
252  d2[0] = (ppositron - p2).Mag();
253  d1[1] = (pelectron - p1).Mag();
254  d2[1] = (pelectron - p2).Mag();
255 
256  Int_t j = 0;
257  if(d1[0]+d2[1]<d1[1]+d2[0]){
258  j = 1;
259  data[32] = eelectron;
260  data[33] = epositron;
261  }
262  for(Int_t i = 0; i<3; i++){
263  if(j){
264  data[10+i] = pelectron[i];
265  data[13+i] = ppositron[i];
266  }else{
267  data[10+i] = ppositron[i];
268  data[13+i] = pelectron[i];
269  }
270  data[16+i] = p1[i];
271  data[19+i] = p2[i];
272  }
273  data[22] = iV;
274 
275 
276 
277 
278 
279 
280  Double_t fWidthX = 50, fWidthZ = 50;
281  Double_t q1[2] = {0,0}, q2[2] = {0,0};
282  for(Int_t plane = 0; plane<2; plane++){
283  HarpoDccMap* m = fEvt->GetDccMap(plane);
284  for(Int_t i=0;i<NADC;i++){ //Time bins
285  for(Int_t j=0;j<NCHAN;j++){ // Channels
286  Double_t q = m->GetData(j,i);
287  if(q<=0) continue;
288  if(TMath::Abs(j-data[plane]-p1[plane]/p1[2]*(i-data[2]))>fWidthX && TMath::Abs(j-data[plane]-p2[plane]/p2[2]*(i-data[2]))>fWidthX ) continue;
289  if(TMath::Abs(i-data[2]-p1[2]/p1[plane]*(j-data[plane]))>fWidthZ && TMath::Abs(i-data[2]-p2[2]/p2[plane]*(j-data[plane]))>fWidthZ) continue;
290  Double_t r = 1; // r is the fraction of area in the sector containing the corner i,j
291  if((i-data[2])*psum[plane]-(j-data[plane])*psum[2]>0) r = 1. - r;
292  q1[plane] += q*r;
293  q2[plane] += q*(1.-r);
294  }
295  }
296  }
297 
298 
299  data[37] = q1[0];
300  data[38] = q1[1];
301  data[39] = q2[0];
302  data[40] = q2[1];
303 
304 
305 
306 
307 
308 
309 
310 
311  fNtuple->Fill(data);
312 
313  }
314 
315 
316 }
317 
319 {
320 
321  fChooseNbins = 0;
322 
323  hDist = new TH1F("hDist","",500,0,500);
324  hP = new TH2F("hP","",100,-1,1,100,-1,1);
325 
326  hOmega = new TH1F("hOmega","",200,-3.5,3.5);
327  hOpen = new TH1F("hOpen","",200,0,3.5);
328  hDeltaOmega = new TH1F("hDeltaOmega","",200,-3.5,3.5);
329  hDeltaOpen = new TH1F("hDeltaOpen","",200,-3.5,3.5);
330  hOmegaSim = new TH1F("hOmegaSim","",200,-3.5,3.5);
331  hOpenSim = new TH1F("hOpenSim","",200,0,3.5);
332  hDiffOpen = new TH1F("hDiffOpen","",200,-0.5,0.5);
333 
334 
335  gBeam = new TGraph2D();
336 
337  fNtuple = new TNtupleD("fNtuple","Vertex data","x0:y0:z0:omega:alpha:omegasim:alphasim:px:py:pz:px1sim:py1sim:pz1sim:px2sim:py2sim:pz2sim:px1:py1:pz1:px2:py2:pz2:iV:pxsim:pysim:pzsim:xS:yS:zS:xsim:ysim:zsim:e1:e2:trig:qBefore:qAfter:qx1:qy1:qx2:qy2");
338  fNtuple->SetDirectory(0);
339 
340 
341  }
342 
343 void HarpoAnalyseVertex3D::Save(char * /* mode */)
344  {
345 
346  OpenHistFile("vertex3d");
347 
348  // Save histograms here
349  hDist->Write();
350  gBeam->Write("gBeam");
351  hP->Write();
352  hOmega->Write();
353  hOpen->Write();
354  hDeltaOmega->Write();
355  hDeltaOpen->Write();
356  hOmegaSim->Write();
357  hOpenSim->Write();
358  hDiffOpen->Write();
359 
360  fNtuple->Write();
361  }
362 
363 
364 
365 void HarpoAnalyseVertex3D::DisplayAnalysis(TRootEmbeddedCanvas* ecTab, TGListBox* /* infobox */)
366 {
367  // in hrecomonitorgui: fills the canvas on the "Analysis" tab
368  TCanvas* c = ecTab->GetCanvas();
369  c->GetPad(1)->Delete();
370  c->GetPad(2)->Delete();
371  c->Divide(2);
372 
373  for(Int_t plane = 0; plane<2;plane++){
374  TVirtualPad* cMap = c->GetPad(plane+1);
375  HarpoDccMap* m = fEvt->GetDccMap(plane);
376  TH2F* h = new TH2F("h","",512,0,512,288,0,288);
377  for(Int_t i=1;i<NADC;i++){ //Time bins
378  for(Int_t j=0;j<NCHAN;j++){ // Channels
379  Double_t q = m->GetData(j,i);
380  h->SetBinContent(i+1,j+1,q);
381  }
382  }
383  h->SetMinimum(0);
384  MakeNiceHisto(h,cMap,"colz");
385  h->Delete();
386  }
387 
388  c->Update();
389 }
390 
391 
392 void HarpoAnalyseVertex3D::ConfigFrame(TGMainFrame* fMain, Int_t id)
393 {
394  // in hrecomonitorgui: Creates a popup window for analysis configuration
395  // You must define SetConfig() properly
396 
397  UInt_t xsize = 200;
398  UInt_t ysize2 = 20;
399  UInt_t ysize = 10*ysize2;
400  TGTransientFrame* main = new TGTransientFrame(gClient->GetRoot(), fMain, xsize, ysize);
401  main->Connect("CloseWindow()", "HarpoRecoMonitorGui", main, "CloseWindow()");
402  main->DontCallClose(); // to avoid double deletions.
403 
404  // use hierarchical cleaning
405  main->SetCleanup(kDeepCleanup);
406 
407  TGVerticalFrame* frame = new TGVerticalFrame(main,xsize,ysize,kVerticalFrame);
408 
409  // Object layout options
410  TGLayoutHints* fLayout1 = new TGLayoutHints(kLHintsLeft ,5,5,5,5);
411  TGLayoutHints* fLayout2 = new TGLayoutHints(kLHintsRight ,5,5,5,5);
412  TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsTop | kLHintsExpandX ,5,5,5,5);
413  TGLayoutHints* fLayout4 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5);
414 
415  //________ DO NOT MODIFY ABOVE _____________________________
416 
417 
418 
419 
420  // Title of the analysis
421  TGLabel* fAnalysisLabel = new TGLabel(frame, "Template analysis");
422 
423  // Create a line for choosing value of parameter
424  TGHorizontalFrame* nBinsFrame = new TGHorizontalFrame(frame,xsize,ysize2,kHorizontalFrame);
425  TGLabel* nBinsLabel = new TGLabel(nBinsFrame, "fNbins");
426  fChooseNbins = new TGNumberEntry(nBinsFrame);
427  fChooseNbins->SetNumber(fNbins);
428 
429  main->AddFrame(frame,fLayout4);
430  frame->AddFrame(fAnalysisLabel,fLayout3);
431  frame->AddFrame(nBinsFrame,fLayout3);
432  nBinsFrame->AddFrame(nBinsLabel,fLayout1);
433  nBinsFrame->AddFrame(fChooseNbins,fLayout2);
434 
435 
436 
437  //________ DO NOT MODIFY BELOW _____________________________
438  // Button to validate configuration
439  TGTextButton* setConf = new TGTextButton(frame,"Save Config",id);
440  setConf->Associate(fMain);
441 
442  frame->AddFrame(setConf,fLayout3);
443 
444  main->MapSubwindows();
445  main->MapWindow();
446  main->Resize();
447  return;
448 }
449 
450 
451 
453 {
454  // Update the configuration according to the values in the popup window
455 
456  if(!fChooseNbins) return;
457 
458  fNbins = fChooseNbins->GetNumber();
459 }
Double_t GetZvertex3D()
Double_t GetYvertex3D()
Dcc Plane Y.
Definition: HarpoDet.h:20
TpcSimIonisationTrack * GetIonisationTrack(Int_t iTr)
TVector3 GetPola()
Definition: TpcSimMCEvent.h:40
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
void ConfigFrame(TGMainFrame *fMain, Int_t id)
TVector3 GetOrigin()
Definition: TpcSimMCEvent.h:27
#define XPLANE
Definition: HarpoConfig.h:24
#define NCHAN
Definition: HarpoDccMap.h:16
TVector3 GetP2Vertex3D()
Int_t GetNtracks()
Definition: HarpoSimEvent.h:54
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 ....
Int_t GetTriggerType()
Definition: Pmm2Event.h:29
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()
Cluster object, containing position, charge and quality information.
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()
TpcSimMCTrack * GetTrack(Int_t i)
Definition: TpcSimMCEvent.h:91
#define NADC
Definition: HarpoDccMap.h:18
void DisplayAnalysis(TRootEmbeddedCanvas *ecTab, TGListBox *infobox)
Redefine empty default.
#define YPLANE
Definition: HarpoConfig.h:25
TGNumberEntry * fChooseNbins
TpcSimMCEvent * GetMCEvent()
Definition: HarpoSimEvent.h:57
A class store HARPO raw PMM2 event buffer and header. End provide access metods to the row data...
Definition: Pmm2Event.h:19
TClonesArray * GetVertex3DArray()
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
void Save(char *mode=NULL)
void print()
Overloaded method which do all job.
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
TClonesArray * GetClustersArray()
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
Double_t GetXvertex3D()
Dummy analysis to run as test and example. Give basic histograms of the data.
3D vertex object, containing position, angle and associated 2D vertexes, and quality info ...