TestAlgorithm.C 4.7 KB
Newer Older
1
2
3
4
5
6
7
#include "TestAlgorithm.h"
#include "Timepix3Pixel.h"
#include "Timepix3Cluster.h"

TestAlgorithm::TestAlgorithm(bool debugging)
: Algorithm("TestAlgorithm"){
  debug = debugging;
8
  makeCorrelations = false;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
}


void TestAlgorithm::initialise(Parameters* par){
 
  parameters = par;
  // Make histograms for each Timepix3
  for(int det = 0; det<parameters->nDetectors; det++){
    
    // Check if they are a Timepix3
    string detectorID = parameters->detectors[det];
    if(parameters->detector[detectorID]->type() != "Timepix3") continue;
    
    // Simple hit map
    string name = "hitmap_"+detectorID;
    hitmap[detectorID] = new TH2F(name.c_str(),name.c_str(),256,0,256,256,0,256);
    
    // Cluster plots
    name = "clusterSize_"+detectorID;
    clusterSize[detectorID] = new TH1F(name.c_str(),name.c_str(),25,0,25);
    name = "clusterTot_"+detectorID;
    clusterTot[detectorID] = new TH1F(name.c_str(),name.c_str(),200,0,1000);
    name = "clusterPositionGlobal_"+detectorID;
    clusterPositionGlobal[detectorID] = new TH2F(name.c_str(),name.c_str(),400,-10.,10.,400,-10.,10.);
    
    // Correlation plots
    name = "correlationX_"+detectorID;
    correlationX[detectorID] = new TH1F(name.c_str(),name.c_str(),1000,-10.,10.);
    name = "correlationY_"+detectorID;
    correlationY[detectorID] = new TH1F(name.c_str(),name.c_str(),1000,-10.,10.);
    name = "correlationTime_"+detectorID;
    correlationTime[detectorID] = new TH1F(name.c_str(),name.c_str(),2000000,-0.5,0.5);
    name = "correlationTimeInt_"+detectorID;
    correlationTimeInt[detectorID] = new TH1F(name.c_str(),name.c_str(),8000,-40000,40000);
    
    // Timing plots
    name = "eventTimes_"+detectorID;
46
    eventTimes[detectorID] = new TH1F(name.c_str(),name.c_str(),3000000,0,30);
47
48
49
50
  }

}

Daniel Hynds's avatar
Daniel Hynds committed
51
StatusCode TestAlgorithm::run(Clipboard* clipboard){
52
53
54
55
56
57
58
59
60
61
62
  
  // Loop over all Timepix3 and make plots
  for(int det = 0; det<parameters->nDetectors; det++){
    
    // Check if they are a Timepix3
    string detectorID = parameters->detectors[det];
    if(parameters->detector[detectorID]->type() != "Timepix3") continue;
		
    // Get the pixels
    Timepix3Pixels* pixels = (Timepix3Pixels*)clipboard->get(detectorID,"pixels");
    if(pixels == NULL){
63
      if(debug) tcout<<"Detector "<<detectorID<<" does not have any pixels on the clipboard"<<endl;
64
      continue;
65
66
67
68
69
70
71
72
73
    }
    
    // Loop over all pixels and make hitmaps
    for(int iP=0;iP<pixels->size();iP++){
      
      // Get the pixel
      Timepix3Pixel* pixel = (*pixels)[iP];
      
      // Hitmap
74
      hitmap[detectorID]->Fill(pixel->m_column,pixel->m_row);
75
76
77
78
79
      
      // Timing plots
      eventTimes[detectorID]->Fill((double)pixel->m_timestamp / (4096.*40000000.) );
      
    }
80
81
82
83
84
85
86

    // Get the clusters
    Timepix3Clusters* clusters = (Timepix3Clusters*)clipboard->get(detectorID,"clusters");
    if(clusters == NULL){
      if(debug) tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
      continue;
    }
87
    
88
89
90
    // Get clusters from reference detector
    Timepix3Clusters* referenceClusters = (Timepix3Clusters*)clipboard->get(parameters->reference,"clusters");
    if(referenceClusters == NULL){
91
92
      if(debug)tcout<<"Reference detector "<<parameters->reference<<" does not have any clusters on the clipboard"<<endl;
//      continue;
93
94
    }

95
96
97
98
99
100
101
102
103
104
105
106
    // Loop over all clusters and fill histograms
    for(int iCluster=0;iCluster<clusters->size();iCluster++){

      // Get the cluster
      Timepix3Cluster* cluster = (*clusters)[iCluster];

      // Fill cluster histograms
      clusterSize[detectorID]->Fill(cluster->size());
      clusterTot[detectorID]->Fill(cluster->tot());
      clusterPositionGlobal[detectorID]->Fill(cluster->globalX(),cluster->globalY());
      
      // Loop over reference plane pixels to make correlation plots
107
      if(!makeCorrelations) continue;
108
      if(referenceClusters == NULL) continue;
109
110
111
112
113
114
115
116
      for(int iRefCluster=0;iRefCluster<referenceClusters->size();iRefCluster++){
        Timepix3Cluster* refCluster = (*referenceClusters)[iRefCluster];
         
        long long int timeDifferenceInt =(refCluster->timestamp() - cluster->timestamp()) / 4096;
        
        double timeDifference = (double)(refCluster->timestamp() - cluster->timestamp()) / (4096.*40000000.);
        
        // Correlation plots
117
118
        if( abs(timeDifference) < 0.000001 ) correlationX[detectorID]->Fill(refCluster->globalX() - cluster->globalX());
        if( abs(timeDifference) < 0.000001 ) correlationY[detectorID]->Fill(refCluster->globalY() - cluster->globalY());
119
120
        correlationTime[detectorID]->Fill( timeDifference );
        correlationTimeInt[detectorID]->Fill( timeDifferenceInt );
121
      }//*/
122
123
124
125
126
127
    }
    
    
    
  }

Daniel Hynds's avatar
Daniel Hynds committed
128
  return Success;
129
130
131
132
133
134
}

void TestAlgorithm::finalise(){
  
  
}