-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdRaw2Ped.C
130 lines (110 loc) · 4.12 KB
/
rdRaw2Ped.C
1
2
3
4
5
6
7
8
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <fstream>
#include <sstream>
#include <math.h>
#include <TROOT.h>
#include <TSystem.h>
#include <TStyle.h>
#include <TString.h>
#include <TError.h>
#include <TFile.h>
#include <TTree.h>
#include <TList.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TDatime.h>
#include <TRandom3.h>
#include <TF1.h>
#include <TColor.h>
#include <CcdPedMaker.hh>
#include <CameraInfo.hh>
#include <Event.hh>
#include <DatasetHeader.hh>
#include <Dataset.hh>
// mode=0 do ALL: read raw & accumulate ped, compute ped & stat--> R*
// mode=1 read raw & accumulate ped --> big_R*
// mode=2 read 1 raw + big_R histo , compued ped & stat --> R*
// Note, you need to manulay mv R* to 'archive' directory
// 'loc' changes with location: loc=0:my VM, loc=1:m3daq
void rdRaw2Ped(int runId=0000001, int mode=0, TString outPath="./", int loc=0){
gSystem->AddIncludePath("-I$DMTPC_HOME/DmtpcCore/include");
gSystem->AddIncludePath("-I$DMTPC_HOME/DmtpcSkim/include");
// load_libs_and_classes();
int doPixelPlots=1;
//TString coreName=Form("dmtpc_m3_%05d",runId);
// TString coreName=Form("m3_Michael_R%07d",runId);
TString coreName=Form("hptpc_test_R%07d",runId);
//TString inpPath="/scratch3/darkmatter/dmtpc/data/m3/2016/03/raw/"; // on m3daq
TString inpPath="/scratch3/wparker2/dmtpc2/data/2017/06/"; // on m3daq
//TString inpPath="/scratch1/darkmatter/dmtpc/data/m3/NoiseStudy/1x1binning/"; // on m3daq
TString inpFile=inpPath+coreName+".raw.root";
//TString inpFile=inpPath+coreName+".root";
// assert(gSystem->Load("$DMTPC_HOME/DmtpcCore/lib/libDmtpcCore.so")==0);
// assert(gSystem->Load("$DMTPC_HOME/DmtpcSkim/lib/libDmtpcSkim.so")==0);
std::cout << "Gets Here" << std::endl;
gSystem->Load("$DMTPC_HOME/DmtpcCore/lib/libDmtpcCore.so");
gSystem->Load("$DMTPC_HOME/DmtpcSkim/lib/libDmtpcSkim.so");
enum { mxCam=4}; // there are 2 cameras for the current gain map data
std::vector<dmtpc::skim::CcdPedMaker> pedMk(mxCam);
for(int i=0;i<pedMk.size();i++){
pedMk[i] = new dmtpc::skim::CcdPedMaker();
}
//dmtpc::skim::CcdPedMaker pedMk[mxCam];
dmtpc::core::Dataset *ds = new dmtpc::core::Dataset;
ds->open(inpFile);
int nExpo=ds->nevents();
printf(" Opened=%s nBias=%d nExpo=%d mode=%d\n", inpFile.Data(), ds->nbias(),nExpo,mode);
assert( nExpo >0);
/* Load first event to get information about CCD data format*/
ds->getEvent(0);
// if(mode!=1 && doPixelPlots) {
//TCanvas *can=new TCanvas("aa","bb");
TCanvas can;
for(int iCam=0;iCam < mxCam; iCam++) {
int camId=iCam;
int camDaq=iCam;
if(mxCam==2) { camId=iCam+2, camDaq=iCam;};
//pedMk[iCam].setUserRebin(4); //degrade CCD resolution
pedMk[iCam].can=can;// tmp
pedMk[iCam].initDims( ds,camId,camDaq);
}
// return;
int time0=time(0);
if (mode<2) {
printf(" pedestal accumulation ...\n");
/******* events loop start *******/
for (int ieve=0; ieve < nExpo; ieve++) {
ds->getEvent(ieve);
dmtpc::core::Event * eve=ds->event();
for(int iCam=0;iCam < mxCam; iCam++)
pedMk[iCam].accumulatePed(eve);
// break; // just one eve
}
int delT=time(0)-time0;
float rate=-1;
if(delT>0)rate= ieve/delT;
printf("tot number frames: inp=%d readRate=%.1fHz elapsed time=%.1f minutes\n",ieve,rate,delT/60.);
} else {
for(int iCam=0;iCam < mxCam; iCam++)
pedMk[iCam].ingest_pedSpecBig(outPath+"/big_"+coreName+".m3ped.root");
}
if (mode!=1) {// compute pedestals & QA
// measure time used for computation of pedestals
time0=time(0);
int nPix=0;
for(int iCam=0;iCam < mxCam; iCam++)
nPix+=pedMk[iCam].computePed();
int delT=time(0)-time0;
float rate=-1;
if(delT>0)rate= nPix/delT;
printf("tot num pix%.1f(k) rate=%.1fkHz, elapsed time=%.0f seconds\n",nPix/1000.,rate/1000.,delT);
}
TString txt1=""; if (mode==1) txt1="big_";
TFile *outHfile=new TFile(outPath+"/"+txt1+coreName+".m3ped.root","recreate");
assert(outHfile->IsOpen());
for(int iCam=0;iCam < mxCam; iCam++)
pedMk[iCam].saveHisto(outHfile,mode);
return;
//cam3_fr0_cal->Draw("lego1 0");
}