Timepix1Correlator.C 3.66 KB
Newer Older
Daniel Hynds's avatar
Daniel Hynds committed
1
#include "Timepix1Correlator.h"
2
3
4
#include "Pixel.h"
#include "Cluster.h"
#include "Track.h"
Daniel Hynds's avatar
Daniel Hynds committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Timepix1Correlator::Timepix1Correlator(bool debugging)
: Algorithm("Timepix1Correlator"){
  debug = debugging;
}


void Timepix1Correlator::initialise(Parameters* par){
 
  parameters = par;

  // Initialise histograms per device
  for(int det = 0; det<parameters->nDetectors; det++){
    
    // Check if they are a Timepix3
    string detectorID = parameters->detectors[det];
    if(parameters->detector[detectorID]->type() != "Timepix1") continue;
    
    // Simple histogram per device
    string name = "correlationsX_"+detectorID;
Daniel Hynds's avatar
Daniel Hynds committed
25
    correlationPlotsX[detectorID] = new TH1F(name.c_str(),name.c_str(),500,-3,3);
Daniel Hynds's avatar
Daniel Hynds committed
26
27

    name = "correlationsY_"+detectorID;
Daniel Hynds's avatar
Daniel Hynds committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    correlationPlotsY[detectorID] = new TH1F(name.c_str(),name.c_str(),500,-3,3);

    int nPixelsRow = parameters->detector[detectorID]->nPixelsY();
    int nPixelsCol = parameters->detector[detectorID]->nPixelsX();
    name = "hitmaps_"+detectorID;
    hitmaps[detectorID] = new TH2F(name.c_str(),name.c_str(),nPixelsCol,0,nPixelsCol,nPixelsRow,0,nPixelsRow);

    name = "hitmapsGlobal_"+detectorID;
    hitmapsGlobal[detectorID] = new TH2F(name.c_str(),name.c_str(),200,-10.,10.,200,-10.,10.);
    
    name = "clusterSize_"+detectorID;
    clusterSize[detectorID] = new TH1F(name.c_str(),name.c_str(),25,0,25);

    name = "clustersPerEvent_"+detectorID;
    clustersPerEvent[detectorID] = new TH1F(name.c_str(),name.c_str(),200,0,200);

Daniel Hynds's avatar
Daniel Hynds committed
44
45
46
47
48
49
50
51
52
53
54

  }
  
  // Initialise member variables
  m_eventNumber = 0;
}

StatusCode Timepix1Correlator::run(Clipboard* clipboard){

  // Get the clusters for the reference detector
  string referenceDetector = parameters->reference;
55
  Clusters* referenceClusters = (Clusters*)clipboard->get(referenceDetector,"clusters");
Daniel Hynds's avatar
Daniel Hynds committed
56
57
58
59
60
61
62
63
  if(referenceClusters == NULL){
    if(debug) tcout<<"Detector "<<referenceDetector<<" does not have any clusters on the clipboard"<<endl;
    return Success;
  }

  // Loop over all Timepix1 and make plots
  for(int det = 0; det<parameters->nDetectors; det++){
    
64
    // Check if they are a Timepix1
Daniel Hynds's avatar
Daniel Hynds committed
65
66
67
68
    string detectorID = parameters->detectors[det];
    if(parameters->detector[detectorID]->type() != "Timepix1") continue;
    
    // Get the clusters
69
    Clusters* clusters = (Clusters*)clipboard->get(detectorID,"clusters");
Daniel Hynds's avatar
Daniel Hynds committed
70
71
72
73
74
75
76
    if(clusters == NULL){
      if(debug) tcout<<"Detector "<<detectorID<<" does not have any clusters on the clipboard"<<endl;
      continue;
    }
    
    // Loop over all clusters and make correlations
    for(int itCluster=0;itCluster<clusters->size();itCluster++){
Daniel Hynds's avatar
Daniel Hynds committed
77
78

      // Get the cluster
79
      Cluster* cluster = (*clusters)[itCluster];
Daniel Hynds's avatar
Daniel Hynds committed
80

Daniel Hynds's avatar
Daniel Hynds committed
81
82
      for(int itRefCluster=0;itRefCluster<referenceClusters->size();itRefCluster++){
      
Daniel Hynds's avatar
Daniel Hynds committed
83
      	// Get the reference cluster
84
        Cluster* refCluster = (*referenceClusters)[itRefCluster];
Daniel Hynds's avatar
Daniel Hynds committed
85
86
      
        // Fill the plots for this device
Daniel Hynds's avatar
Daniel Hynds committed
87
88
        if(fabs(cluster->globalY()-refCluster->globalY()) < 1.) correlationPlotsX[detectorID]->Fill(cluster->globalX()-refCluster->globalX());
        if(fabs(cluster->globalX()-refCluster->globalX()) < 1.) correlationPlotsY[detectorID]->Fill(cluster->globalY()-refCluster->globalY());
Daniel Hynds's avatar
Daniel Hynds committed
89
      }
Daniel Hynds's avatar
Daniel Hynds committed
90
91
92
93
      
      hitmaps[detectorID]->Fill(cluster->column(),cluster->row());
      hitmapsGlobal[detectorID]->Fill(cluster->globalX(),cluster->globalY());
      clusterSize[detectorID]->Fill(cluster->size());
Daniel Hynds's avatar
Daniel Hynds committed
94
    }
Daniel Hynds's avatar
Daniel Hynds committed
95
    clustersPerEvent[detectorID]->Fill(m_eventNumber,clusters->size());
Daniel Hynds's avatar
Daniel Hynds committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  }
  
  // Increment event counter
  m_eventNumber++;
  
  // Return value telling analysis to keep running
  return Success;
}

void Timepix1Correlator::finalise(){
  
  if(debug) tcout<<"Analysed "<<m_eventNumber<<" events"<<endl;
  
}