source: trunk/Mars/macros/fact/drscal.C@ 15732

Last change on this file since 15732 was 14932, checked in by tbretz, 12 years ago
Macro to re-calculate the drs calibration constants (.drs.fits files)
File size: 4.0 KB
Line 
1int drscal(const char *drsname="~dorner/mysequences/2012/02/28/20120228_200.drs.seq", const char *outpath = "output")
2{
3 // ======================================================
4
5 const char *map = "/scratch_nfs/FACTmap111030.txt";
6
7 // ======================================================
8
9 if (map && gSystem->AccessPathName(map, kFileExists))
10 {
11 gLog << "ERROR - Cannot access mapping file '" << map << "'" << endl;
12 return 1;
13 }
14
15 // The sequence file which defines the files for the analysis
16 MSequence drs(drsname);
17 if (!drs.IsValid())
18 {
19 gLog << "ERROR - Sequence '" << drsname << "' invalid!" << endl;
20 return 2;
21 }
22
23 // DrsRuns 1
24 // CalRuns 1
25 // DrsFiles 1 [1024], PedRuns 1 [300]
26
27 // --------------------------------------------------------------------------------
28
29 gLog.Separator("DRS Calibration");
30 gLog << "Calculate drs calibration constants of drs sequence:\n" << drs.GetFileName() << endl;
31 gLog << endl;
32
33 // ------------------------------------------------------
34
35 TString drsped = drs.GetFileName(0, MSequence::kFitsDrsRuns);
36 TString drsgain = drs.GetFileName(0, MSequence::kFitsCal);
37 TString drs1024 = drs.GetFileName(1, MSequence::kFitsDrsRuns);
38 TString drs300 = drs.GetFileName(0, MSequence::kFitsPed);
39
40 gLog << "DRS ped 1024: " << drsped << '\n';
41 gLog << "DRS gain 1024: " << drsgain << '\n';
42 gLog << "DRS ped 1024: " << drs1024 << "\n";
43 gLog << "DRS ped 300: " << drs300 << endl;
44
45 // ======================================================
46
47 MStatusDisplay *d = new MStatusDisplay;
48
49 MParList plist;
50
51 MHDrsCalibration hist;
52 plist.AddToList(&hist);
53
54 hist.SetOutputPath(outpath);
55
56 MTaskList tlist;
57 plist.AddToList(&tlist);
58
59 MEvtLoop loop;
60 loop.SetParList(&plist);
61 loop.SetDisplay(d);
62
63 // --------------------------------------------------------
64
65 gLog.Separator("Calculating cell offset");
66
67 MRawFitsRead read1(drsped);
68 read1.LoadMap(map);
69
70 MGeomApply apply;
71
72 tlist.AddToList(&read1);
73 tlist.AddToList(&apply);
74
75 MFillH fill("MHDrsCalibration");
76 fill.SetNameTab("Ped1");
77
78 tlist.AddToList(&fill);
79
80 if (!loop.Eventloop())
81 return 3;
82
83 if (!loop.GetDisplay())
84 return 4;
85
86 // --------------------------------------------------------
87
88 gLog.Separator("Calculating cell gain");
89
90 MRawFitsRead read2(drsgain);
91 read2.LoadMap(map);
92 tlist.Replace(&read2);
93 fill.SetNameTab("Gain");
94
95 if (!loop.Eventloop())
96 return 5;
97
98 if (!loop.GetDisplay())
99 return 6;
100
101 // --------------------------------------------------------
102
103 gLog.Separator("Calculating drs constants for roi=1024");
104
105 fill.SetNameTab("Ped2-1024");
106
107 // I think one HAS to use the same file than for step one
108 // this is the only way to get rid of a systematic shift.
109 MRawFitsRead read3(drs1024);
110 read3.LoadMap(map);
111 tlist.Replace(&read3);
112
113 if (!loop.Eventloop())
114 return 7;
115
116 if (!loop.GetDisplay())
117 return 8;
118
119 // --------------------------------------------------------
120
121 gLog.Separator("Calculating drs constants for roi=300");
122
123 fill.SetNameTab("Ped2-300");
124
125 if (!hist.ResetSecondaryBaseline())
126 {
127 cout << "ERROR - Reset failed." << endl;
128 return 100;
129 }
130
131 // I think one HAS to use the same file than for step one
132 // this is the only way to get rid of a systematic shift.
133 MRawFitsRead read4(drs300);
134 read4.LoadMap(map);
135 tlist.Replace(&read4);
136
137 if (!loop.Eventloop())
138 return 9;
139
140 if (!loop.GetDisplay())
141 return 10;
142
143 // --------------------------------------------------------
144
145 TString title = "-- DRS Calibration #";
146 title += drs.GetSequence();
147 title += " (";
148 title += drsname;
149 title += ") --";
150 d->SetTitle(title, kFALSE);
151
152 TString path;
153 path += Form("%s/20%6d_%03d-drs.root", outpath,
154 drs.GetSequence()/1000, drs.GetSequence()%1000);
155
156 d->SaveAs(path);
157
158 return 0;
159
160}
Note: See TracBrowser for help on using the repository browser.