source: branches/MarsISDCBranchBasedOn17887/macros/datatrigcheck.C@ 18066

Last change on this file since 18066 was 3536, checked in by stamerra, 21 years ago
*** empty log message ***
File size: 6.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Nicola Galante, 3/2004 <mailto:nicola.galante@pi.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// datatrigcheck
28//
29// This macro is the standard trigger's parameters checking stuff
30//
31//
32/////////////////////////////////////////////////////////////////////////////
33Double_t myPoisson(Double_t *x, Double_t *par)
34{
35 Double_t a=0.0, b=0.0, c=0.0;
36 Double_t fitval = 0.0;
37
38 Int_t floorX = (Int_t)TMath::Floor(x[0]);
39 a = TMath::Power(par[0],floorX);
40 b = TMath::Exp(-par[0]);
41 c = TMath::Factorial(floorX);
42
43 if (c!=0)
44 fitval = par[1]*a*b/c;
45
46 return fitval;
47}
48
49Double_t myExp(Double_t *x, Double_t *par)
50{
51 Double_t a=0.0;
52 Double_t fitval = 0.0;
53
54 a = TMath::Exp(-x[0]);
55 fitval = par[0]*a;
56
57 return fitval;
58}
59
60// The macro
61// Input:
62// 1. The directory path starting from the Period (the complete path is
63// written in the basedir variable)
64// 2. The data filename (without extension)
65//
66void datatrigcheck(TString dirin="Period014/rootdata/2004_02_17/", TString filein="20040117_03695_D_Crab-On_E")
67{
68
69 // Set file name and INPUT and OUTPUT directories
70
71 TString basedir="/data1/earth/magic/data/";
72
73 TString filenamein(filein);
74 TString dirnamein(dirin);
75
76 dirnamein = basedir+dirnamein;
77 filenamein = dirnamein + filein + ".root";
78
79 // Here the output plots are saved
80 TString webdatadir = basedir + "webdata/" + filein + "/";
81
82 //
83 // Create a empty Parameter List and an empty Task List
84 // The tasklist is identified in the eventloop by its name
85 //
86 MParList plist;
87 MTaskList tlist;
88
89 plist.AddToList(&tlist);
90
91 MReadMarsFile read("Events");
92 read.DisableAutoScheme();
93 read.AddFile(filenamein);
94
95 tlist.AddToList(&read);
96
97 //
98 // Extract Number of events
99 //
100 const Int_t numEvt = read.GetEntries();
101
102 cout << "Opened file " << filenamein << " with "<< numEvt << " events." << endl;
103 // ==================
104 // Create histos
105 // FIXME: should be created using MH or similar?
106
107 // HISTcom-hTrigPatternEvt
108 // The trigger pattern is shown as a decimal number
109 // The trigger pattern consists of 16 bits (8+8 bits) generated by the trigger system.
110 // The first 8 bits correspond to the trigger configuration before the prescaling,
111 // the others after prescaling.
112 // Bit structure:
113 // not prscd | prscaled
114 // xxxx xxxx xxxx xxxx <-- pattern (x=0,1)
115 // bit 7654 3210 7654 3210
116 //
117 TH1I *hTrigPatternEvt = new TH1I("hTrigPatternEvt","Trigger Pattern vs. Event Number",numEvt,0,(Axis_t)numEvt);
118
119 // HISTcom-hTimeEvt
120 // Absolute time vs event number
121 // The Absolute time has been calculated using the MTime->GetTime() (millisec) and the MTime->GetMjd() (nanosec)
122 TH1D *hTimeEvt = new TH1D("hTimeEvt","DAQ Time vs. Event Number",numEvt,0,(Axis_t)numEvt);
123
124 // HISTcom-hTimeDiffEvt
125 TH1D *hTimeDiffEvt = new TH1D("hTimeDiffEvt","Differences of time vs. Event Number",numEvt-1,0,(Axis_t)numEvt-1);
126
127 // HISTcom-hTimeDiff
128 TH1D *hTimeDiff = new TH1D("hTimeDiff","Distribution of differences of time (ns)",200,0,1000000);
129
130
131 TF1 *func1 = new TF1("myPoisson",myPoisson,0,10,2);
132 TF1 *func2 = new TF1("myExp",myExp,0,10,1);
133
134 cout << "*func defined" << endl;
135 func1->SetParameters(1.0,1.0);
136 func2->SetParameter(0,400.0);
137 cout << "parameters setted" << endl;
138 func1->SetParNames("MU","CONST");
139 func2->SetParNames("A");
140
141 //
142 // Create and set up the eventloop
143 //
144 MProgressBar bar;
145
146 MEvtLoop evtloop;
147 evtloop.SetProgressBar(&bar);
148 evtloop.SetParList(&plist);
149
150 Double_t tOld; // buffer variable
151 Double_t tMin = 1E+10;
152 Double_t tMax = -1E+10;
153 Double_t DAQNumMin = 1E+10;
154 //
155 // Execute your analysis
156 //
157 //if (!evtloop.Eventloop())
158 // return;
159 if (!evtloop.PreProcess())
160 return;
161
162 while (tlist.Process())
163 {
164 // Create the container MRawEvtHeader where time and trigger
165 // info are read and stored.
166 MRawEvtHeader *evtHeader = (MRawEvtHeader *)plist->FindObject("MRawEvtHeader");
167 MTime *evtTime = (MTime *)plist->FindObject("MTime");
168
169 Long_t ms = evtTime->GetTime();
170 Double_t ns = ((evtTime->GetMjd()-TMath::Floor(evtTime->GetMjd()))*(Double_t)evtTime->kDay-(Double_t)ms)*1E+6;
171 Double_t t = (Double_t)ms+ns/1.E+6;
172 if (t<tMin) tMin=t;
173
174 // Fill the histos
175 hTrigPatternEvt->Fill(evtHeader->GetDAQEvtNumber(),evtHeader->GetTriggerID());
176 hTimeEvt->Fill(evtHeader->GetDAQEvtNumber(),t);
177 if (evtHeader->GetDAQEvtNumber() != 0){
178 hTimeDiffEvt->Fill(evtHeader->GetDAQEvtNumber(),t-tOld);
179 hTimeDiff->Fill((t-tOld)*1E+6);
180 }
181 if (t-tOld > tMax) tMax = t-tOld;
182 tOld = t;
183 }
184
185 //TString command = "./macros/create_web_folder.sh " + webdatadir + filein ;
186
187 // Create new directory with the same name of the run.
188 // Delete old content.
189 //
190 TString command = "mkdir -p " + webdatadir ;
191 system ( command.Data() ) ;
192 command = "rm -f " + webdatadir + "*.gif" ;
193 system ( command.Data() ) ;
194 command = "rm -f " + webdatadir + "*.txt" ;
195 system ( command.Data() ) ;
196
197 tlist.PrintStatistics();
198
199 // Draw Plots and save them as gif images
200 //
201 c1 = new TCanvas( "c1" );
202 hTrigPatternEvt->SetXTitle("Event");
203 hTrigPatternEvt->SetYTitle("Trigger Pattern");
204 hTrigPatternEvt->Draw();
205 c1->Print(webdatadir+hTrigPatternEvt->GetName()+".gif");
206
207 c2 = new TCanvas( "c2" );
208 hTimeEvt->SetXTitle("Event");
209 hTimeEvt->SetYTitle("Abs. time (ms)");
210 hTimeEvt->SetMinimum(tMin);
211 hTimeEvt->Draw();
212 c2->Print(webdatadir+hTimeEvt->GetName()+".gif");
213
214 c3 = new TCanvas( "c3" );
215 hTimeDiffEvt->SetXTitle("Event");
216 hTimeDiffEvt->SetYTitle("Time diff (ms)");
217 hTimeDiffEvt->SetMaximum(tMax*1.1);
218 hTimeDiffEvt->Draw();
219 c3->Print(webdatadir+hTimeDiffEvt->GetName()+".gif");
220
221 c4 = new TCanvas( "c4" );
222 hTimeDiff->SetXTitle("Time diff. (ms)");
223 hTimeDiff->SetYTitle("Events");
224 hTimeDiff->Draw();
225 c4->Print(webdatadir+hTimeDiff->GetName()+".gif");
226
227}
Note: See TracBrowser for help on using the repository browser.