HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseTemplate.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseTemplate.cxx
3 //
11 #include "HarpoAnalyseTemplate.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 #include "HarpoTools.h"
23 
24 #include "TFile.h"
25 #include "TStyle.h"
26 #include "TCanvas.h"
27 #include "TRootEmbeddedCanvas.h"
28 #include "TLatex.h"
29 #include "TGraph.h"
30 #include "TF1.h"
31 #include "TMath.h"
32 #include "TGLabel.h"
33 #include "TSystem.h"
34 
35 #include <cstdlib>
36 #include <cstring>
37 #include <cassert>
38 #include <fstream>
39 #include <iostream>
40 
41 ClassImp(HarpoAnalyseTemplate)
42 
43 void HarpoAnalyseTemplate::print()
44  {
45  unsigned int nd; // number of detectors
46  HarpoEventHeader *hdr = fEvt->GetHeader();
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 
63  // Process RAW data
64  for(Int_t ndet=0;ndet<2;ndet++) { // Detectors 0 and 1 = X and Y planes
65  if (!gHDetSet->isExist(ndet)) continue;
66  HarpoDccMap* m = fEvt->GetDccMap(ndet);
67  if ( m == NULL ) continue;
68  for(Int_t j=0;j<NCHAN;j++){ // Channels
69  //Double_t qch = 0;
70  for(Int_t i=0;i<NADC;i++){ // Time bins
71  Double_t q = m->GetData(j,i);
72  if(q <= -1000) continue;
73  hQraw[ndet]->Fill(q);
74  }
75  }
76  }
77 
78  if(gHDetSet->isExist(PMM2)) { // PMm2 (trigger) data
79  Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
80  // Int_t triggerType = anaEvt->GetTriggerType(); // Trigger line (with mesh, without, traversing tracks, ...)
81 
82  int imes;
83  int esize = anaEvt->GetHeader()->eventSize; // number of PMs hit
84  Pmm2MesVect * pm = anaEvt->GetMesurements(); // data for each included PM
85  for(imes=0;imes<esize;imes++) {
86  int ch = pm->at(imes).getChNum(); // channel
87  int q = pm->at(imes).getCharge(); // charge
88  hPmm2->Fill(ch,q);
89  }
90  }
91 
92  Double_t data[5] = {-1,-1,-1,-1,-1};
93 
94 
95  //???????????????????????????????
96  if(fEvt->GetRecoEvent()){ // Reconstructed data (clusters, tracks, matched tracks)
97  HarpoRecoEvent* reco = fEvt->GetRecoEvent();
98  // Clusters in the event (both X and Y directions)
99  TClonesArray* clArray = reco->GetClustersArray();
100  Int_t nCl = clArray->GetEntries();
101  Int_t nClX = 0, nClY = 0;
102  for(Int_t icl = 0; icl<nCl; icl++){
103  HarpoRecoClusters* cluster = (HarpoRecoClusters*)clArray->At(icl);
104  Double_t q = cluster->GetQ();
105  Int_t plane = cluster->GetPlane();
106  if(plane==XPLANE) nClX++;
107  if(plane==YPLANE) nClY++;
108  hQ[plane]->Fill(q);
109  }
110  // Tracks in the event (both X and Y directions)
111  TClonesArray* trArray = reco->GetTracksArray();
112  Int_t nTr = trArray->GetEntries();
113  Int_t nTrX = 0, nTrY = 0;
114  for(Int_t itr = 0; itr<nTr; itr++){
115  HarpoRecoTracks* track = (HarpoRecoTracks*)trArray->At(itr);
116  // Double_t id = track->GetNtrack();
117  Double_t angle = track->GetAngleTrack();
118  hAngle->Fill(angle);
119  Int_t plane = track->GetPlane();
120  if(plane==XPLANE) nTrX++;
121  if(plane==YPLANE) nTrY++;
122  }
123  // 2D Vertexes in the event (both X and Y directions)
124  TClonesArray* vArray = reco->GetVertexArray();
125  Int_t nV = vArray->GetEntries();
126  Int_t nVx = 0, nVy = 0;
127  for(Int_t iV = 0; iV<nV; iV++){
128  HarpoRecoVertex* vertex = (HarpoRecoVertex*)vArray->At(iV);
129  Int_t plane = vertex->GetPlane();
130  if(plane==XPLANE) nVx++;
131  if(plane==YPLANE) nVy++;
132  }
133  data[0] = nTrX;
134  data[1] = nTrY;
135  data[2] = nClX;
136  data[3] = nClY;
137  }
138 
139 
140 
141 
142  if (gHDetSet->isExist(SIMDET)){
144  Int_t nIonTr = simEvt->GetNtracks();
145  for(Int_t i = 0; i<nIonTr; i++){
146  TpcSimIonisationTrack* tr = simEvt->GetIonisationTrack(i);
147  Int_t nPoints = tr->GetNpoints();
148  for(Int_t j = 0; j<nPoints; j++){
149  TpcSimIonisationPoint* point = tr->GetPoint(j);
150  hNeSim->Fill(point->GetNe());
151  }
152  }
153  TpcSimMCEvent* mcEvent = simEvt->GetMCEvent();
154  Int_t nMCtr = mcEvent->GetNtracks();
155  data[4] = nMCtr;
156  for(Int_t i = 0; i<nMCtr; i++){
157  TpcSimMCTrack* track = mcEvent->GetTrack(i);
158  hPsim->Fill(track->GetPx(),track->GetPy(),track->GetPz());
159  }
160  }
161 
162 
163  Double_t energy = getDoubleVal(run,"Ephoton",dburl);
164  cout << "Energy = " << energy << endl;
165 
166 
167  fNtuple->Fill(data);
168 
169 }
170 
172 {
173 
174  fChooseNbins = 0;
175 
176  // Initialise histograms here
177  fNbins = 500;
178  Double_t fQmin = 10, fQmax = 1e7;
179 
180  Long64_t Nbins;
181  if( ! gHConfig->Lookup("template.nbins",Nbins ))
182  Info("Constructor","Use default fnbinr %d",fNbins);
183  else
184  fNbins = Nbins;
185 
186  Double_t qmin;
187  if( ! gHConfig->Lookup("template.qmin",qmin ))
188  Info("Constructor","Use default Qmin %.3g",fQmin);
189  else
190  fQmin = qmin;
191 
192  Double_t qmax;
193  if( ! gHConfig->Lookup("template.qmax",qmax ))
194  Info("Constructor","Use default Qmax %.3g",fQmax);
195  else
196  fQmax = qmax;
197 
198 
199  hQ[XPLANE] = HistLog("hQx","",fNbins,fQmin,fQmax);
200  hQ[YPLANE] = HistLog("hQy","",fNbins,fQmin,fQmax);
201  hNeSim = new TH1F("hNeSim","",500,0,500);
202  hAngle = new TH1F("hAngle","",500,-10,10);
203  hQraw[XPLANE] = new TH1F("hQrawX","",500,-500,5500);
204  hQraw[YPLANE] = new TH1F("hQrawY","",500,-500,5500);
205  hPmm2 = new TH2F("hPmm2","",16,0,16,128,0,4096);
206  hPsim = new TH3F("hPsim","",20,-1,1,20,-1,1,20,-1,1);
207 
208 
209  fNtuple = new TNtupleD("fNtuple","","nTrX:nTrY:nClX:nClY:nTrsim");
210 
211  }
212 
213 void HarpoAnalyseTemplate::Save(char * /* mode */)
214  {
215 
216  OpenHistFile("template");
217 
218  // Save histograms here
219  hQ[XPLANE]->Write();
220  hQ[YPLANE]->Write();
221  hQraw[XPLANE]->Write();
222  hQraw[YPLANE]->Write();
223  hNeSim->Write();
224  hAngle->Write();
225  hPmm2->Write();
226  hPsim->Write();
227 
228  }
229 
230 
231 
232 void HarpoAnalyseTemplate::DisplayAnalysis(TRootEmbeddedCanvas* ecTab, TGListBox* /* infobox */ )
233 {
234  // in hrecomonitorgui: fills the canvas on the "Analysis" tab
235  TCanvas* c = ecTab->GetCanvas();
236  c->GetPad(1)->Delete();
237  c->GetPad(2)->Delete();
238  c->Divide(2);
239 
240  for(Int_t plane = 0; plane<2;plane++){
241  TVirtualPad* cMap = c->GetPad(plane+1);
242  HarpoDccMap* m = fEvt->GetDccMap(plane);
243  TH2F* h = new TH2F("h","",512,0,512,288,0,288);
244  for(Int_t i=1;i<NADC;i++){ //Time bins
245  for(Int_t j=0;j<NCHAN;j++){ // Channels
246  Double_t q = m->GetData(j,i);
247  h->SetBinContent(i+1,j+1,q);
248  }
249  }
250  h->SetMinimum(0);
251  MakeNiceHisto(h,cMap,"colz");
252  h->Delete();
253  }
254 
255  c->Update();
256 }
257 
258 
259 void HarpoAnalyseTemplate::ConfigFrame(TGMainFrame* fMain, Int_t id)
260 {
261  // in hrecomonitorgui: Creates a popup window for analysis configuration
262  // You must define SetConfig() properly
263 
264  UInt_t xsize = 200;
265  UInt_t ysize2 = 20;
266  UInt_t ysize = 10*ysize2;
267  TGTransientFrame* main = new TGTransientFrame(gClient->GetRoot(), fMain, xsize, ysize);
268  main->Connect("CloseWindow()", "HarpoRecoMonitorGui", main, "CloseWindow()");
269  main->DontCallClose(); // to avoid double deletions.
270 
271  // use hierarchical cleaning
272  main->SetCleanup(kDeepCleanup);
273 
274  TGVerticalFrame* frame = new TGVerticalFrame(main,xsize,ysize,kVerticalFrame);
275 
276  // Object layout options
277  TGLayoutHints* fLayout1 = new TGLayoutHints(kLHintsLeft ,5,5,5,5);
278  TGLayoutHints* fLayout2 = new TGLayoutHints(kLHintsRight ,5,5,5,5);
279  TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsTop | kLHintsExpandX ,5,5,5,5);
280  TGLayoutHints* fLayout4 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5);
281 
282  //________ DO NOT MODIFY ABOVE _____________________________
283 
284 
285 
286 
287  // Title of the analysis
288  TGLabel* fAnalysisLabel = new TGLabel(frame, "Template analysis");
289 
290  // Create a line for choosing value of parameter
291  TGHorizontalFrame* nBinsFrame = new TGHorizontalFrame(frame,xsize,ysize2,kHorizontalFrame);
292  TGLabel* nBinsLabel = new TGLabel(nBinsFrame, "fNbins");
293  fChooseNbins = new TGNumberEntry(nBinsFrame);
294  fChooseNbins->SetNumber(fNbins);
295 
296  main->AddFrame(frame,fLayout4);
297  frame->AddFrame(fAnalysisLabel,fLayout3);
298  frame->AddFrame(nBinsFrame,fLayout3);
299  nBinsFrame->AddFrame(nBinsLabel,fLayout1);
300  nBinsFrame->AddFrame(fChooseNbins,fLayout2);
301 
302 
303 
304  //________ DO NOT MODIFY BELOW _____________________________
305  // Button to validate configuration
306  TGTextButton* setConf = new TGTextButton(frame,"Save Config",id);
307  setConf->Associate(fMain);
308 
309  frame->AddFrame(setConf,fLayout3);
310 
311  main->MapSubwindows();
312  main->MapWindow();
313  main->Resize();
314  return;
315 }
316 
317 
318 
320 {
321  // Update the configuration according to the values in the popup window
322 
323  if(!fChooseNbins) return;
324 
325  fNbins = fChooseNbins->GetNumber();
326 }
Dcc Plane Y.
Definition: HarpoDet.h:20
TpcSimIonisationTrack * GetIonisationTrack(Int_t iTr)
HarpoRecoEvent * GetRecoEvent()
Definition: HarpoEvent.h:46
#define XPLANE
Definition: HarpoConfig.h:24
#define NCHAN
Definition: HarpoDccMap.h:16
void DisplayAnalysis(TRootEmbeddedCanvas *ecTab, TGListBox *infobox)
Redefine empty default.
Dummy analysis to run as test and example. Give basic histograms of the data.
Double_t GetPz()
Definition: TpcSimMCEvent.h:32
Int_t GetNtracks()
Definition: HarpoSimEvent.h:54
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
void Save(char *mode=NULL)
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
Double_t GetAngleTrack()
Track object, containing position, angle, charge and quality information.
Object containing the reconstruction information for one event (with array of HarpoRecoClusters Harpo...
UInt_t eventSize
Raw Event size.
Definition: HarpoDetEvent.h:28
TH1F * HistLog(const char *name, const char *title, Int_t nBins, Double_t xMin, Double_t xMax)
2D vertex object, containing position, angle and associated track numbers, and quality info ...
virtual void print()
Double_t GetPy()
Definition: TpcSimMCEvent.h:31
TpcSimIonisationPoint * GetPoint(Int_t i)
FullEvent Header not scecific to the detectors The class is ....
TGNumberEntry * fChooseNbins
TClonesArray * GetVertexArray()
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.
Int_t getCharge() const
Definition: Pmm2Mes.h:52
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
Pmm2MesVect * GetMesurements()
Return pointer to decoded data.
Definition: Pmm2Event.cxx:78
Data from Keller temperuture and pressure sensors.
Definition: HarpoDet.h:22
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
#define YPLANE
Definition: HarpoConfig.h:25
Double_t getDoubleVal(Int_t run, const char *name, const TString *dburl=NULL)
TpcSimMCEvent * GetMCEvent()
Definition: HarpoSimEvent.h:57
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
A class store HARPO raw PMM2 event buffer and header. End provide access metods to the row data...
Definition: Pmm2Event.h:19
virtual const EventHeader_t * GetHeader() const
Definition: HarpoDetEvent.h:38
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
Int_t getChNum() const
Definition: Pmm2Mes.h:28
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
HarpoConfig * gHConfig
TClonesArray * GetTracksArray()
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
A list of all mesurements in one Event for Pmm2 v2 card The class is place holder for all unpacked me...
Definition: Pmm2MesList.h:19
void ConfigFrame(TGMainFrame *fMain, Int_t id)
Pmm2Mes at(ULong_t idx)
Definition: Pmm2MesList.h:37
Double_t GetPx()
Definition: TpcSimMCEvent.h:30
TClonesArray * GetClustersArray()
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71