/[PAMELA software]/calo/flight/FUTILITIES/macros/FCaloMATRA.cxx
ViewVC logotype

Contents of /calo/flight/FUTILITIES/macros/FCaloMATRA.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Wed Mar 22 15:07:46 2006 UTC (18 years, 8 months ago) by mocchiut
Branch: FUTILITIES
CVS Tags: start, v1r03, v1r01
Changes since 1.1: +0 -0 lines
Flight Utilities calorimeter package 1st release

1 //
2 // Shows calorimeter tracks - Emiliano Mocchiutti
3 //
4 // FCaloMATRA.cxx version 1.01 (2006-03-07)
5 //
6 // The only input needed is the path to the directory created by YODA for the data file you want to analyze.
7 //
8 // Changelog:
9 //
10 // 1.00 - 1.01 (2006-03-07): Flight version, read unique YODA file.
11 //
12 // 0.00 - 1.00 (2006-03-07): Clone of CaloMATARA v3r00.
13 //
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <stdio.h>
17 #include <fstream>
18 #include <sstream>
19 #include <TTree.h>
20 #include <TObjectTable.h>
21 #include <TClassEdit.h>
22 #include <TObject.h>
23 #include <TList.h>
24 #include <TSystem.h>
25 #include <TSystemDirectory.h>
26 #include <TString.h>
27 #include <TFile.h>
28 #include <TClass.h>
29 #include <TCanvas.h>
30 #include <TH1.h>
31 #include <TH1F.h>
32 #include <TH2D.h>
33 #include <TLatex.h>
34 #include <TPad.h>
35 #include <TPaveLabel.h>
36 #include <TChain.h>
37 #include <TApplication.h>
38 #include <TStyle.h>
39 extern bool existfile(TString);
40 extern void stringcopy(TString&, const TString&, Int_t, Int_t);
41 extern void ColorMIP(Float_t, int&);
42 extern Int_t WhatToDo(int&, int&, int&, Long64_t, Float_t, Float_t, const char*, TString, TString, TCanvas&);
43 extern TString getFilename(const TString);
44 extern void *processevents(void *);
45 //
46 #include <caloclassesfun.h>
47 //
48 using namespace std;
49
50
51 void FCaloMATRA(TString filename, Int_t fromevent = 1, Int_t toevent = 0, TString tyhist="box", TString outDir = "", TString saveas = "gif"){
52 Int_t doflag = 1;
53 TApplication *app;
54 if ( !gROOT->GetListOfClasses()->FindObject("TRint") ){
55 //
56 app = new TApplication("app",0,0);
57 };
58 const char* startingdir = gSystem->WorkingDirectory();
59 if ( !strcmp(outDir.Data(),"") ) outDir = startingdir;
60 if ( !existfile(filename) ){
61 printf(" %s :no such file or directory \n",filename.Data());
62 printf("\n ERROR: No calorimeter LEVEL1 file! \n\n Run FCaloLEVEL1 to generate level1 data. \n\n");
63 return;
64 };
65 //
66 TFile *File = new TFile(filename.Data());
67 TTree *otr = (TTree*)File->Get("CaloLevel1");
68 if ( !otr ){
69 printf(" %s are you sure? I need a LEVEL1 file! \n",filename.Data());
70 return;
71 };
72 //
73 CalorimeterLevel1 *calo = new CalorimeterLevel1();
74 otr->SetBranchAddress("Event", &calo);
75 //
76 Long64_t nevents = otr->GetEntries();
77 stringstream titolo;
78 stringstream stringa;
79 TString fififile = getFilename(filename);
80 const char *file = fififile;
81 //
82 //
83 // input limits
84 //
85 if ( tyhist != "box" && tyhist != "lego" ) {
86 printf("You can choose tyhist as box (default) or lego \n");
87 return;
88 };
89
90 if ( fromevent > toevent && toevent ){
91 printf("It must be fromevent < toevent \n");
92 return;
93 };
94
95
96 if ( fromevent > nevents+1 || fromevent < 0 ) {
97 printf("You can choose fromevent between 0 (all) and %i \n",(int)nevents+1);
98 return;
99 };
100
101 if ( toevent > nevents+1 || toevent < 0 ) {
102 printf("You can choose toevent between 0 (all) and %i \n",(int)nevents+1);
103 return;
104 };
105 Int_t minevent = 0;
106 Int_t maxevent = nevents;
107 if ( fromevent == 0 ) {
108 minevent = 0;
109 maxevent = nevents;
110 } else {
111 minevent = fromevent - 1;
112 if ( toevent > 0 ){
113 maxevent = toevent - 1;
114 } else {
115 maxevent = fromevent -1;
116 };
117 };
118
119 //
120 // run over all the events
121 //
122 TCanvas *figura2 = new TCanvas("Calorimeter_tracks", "Calorimeter_tracks", 750, 650);
123 figura2->SetFillColor(10);
124 figura2->Range(0,0,100,100);
125 Int_t i = minevent;
126 while ( i < maxevent+1 ){
127 figura2->Clear();
128 //
129 // variables definition
130 //
131 Int_t badstrip = 0;
132 //
133 // Book the histograms:
134 //
135 //
136 stringstream xview;
137 xview.str("");
138 xview << "x-view event " << (i+1);
139 stringstream yview;
140 yview.str("");
141 yview << "y-view event " << (i+1);
142 gDirectory->Delete(xview.str().c_str());
143 gDirectory->Delete(yview.str().c_str());
144 TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
145 TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
146 //
147 // figures:
148 //
149 Int_t bgcolor = 10;
150 TLatex *t=new TLatex();
151 t->SetTextFont(32);
152 t->SetTextColor(1);
153 t->SetTextSize(0.03);
154 t->SetTextAlign(12);
155 titolo.str("");
156 titolo << "Calorimeter tracks - file " << file;
157 titolo << " - event number " << (i+1);
158 t->DrawLatex(0.5,97.,titolo.str().c_str());
159 Float_t paddim = 0.88;
160 if ( !strcmp(tyhist.Data(),"lego") ){
161 paddim = 0.98;
162 } else {
163 paddim = 0.88;
164 };
165 TPad *pd1 = new TPad("pd1","This is pad1",0.02,0.05,paddim,0.49,bgcolor);
166 TPad *pd2 = new TPad("pd2","This is pad2",0.02,0.51,paddim,0.95,bgcolor);
167 TPad *palette = 0;
168 figura2->cd();
169 pd1->Range(0,0,100,100);
170 pd2->Range(0,0,100,100);
171 pd1->SetTicks();
172 pd2->SetTicks();
173 pd1->Draw();
174 pd2->Draw();
175 if ( !strcmp(tyhist.Data(),"box") ){
176 palette = new TPad("palette","This is palette",0.90,0.05,0.98,0.9,bgcolor);
177 figura2->cd();
178 t=new TLatex();
179 t->SetTextFont(32);
180 t->SetTextColor(1);
181 t->SetTextSize(0.03);
182 t->SetTextAlign(12);
183 t->DrawLatex(92.,92.5,"MIP");
184 palette->Range(0,0,100,100);
185 palette->Draw();
186 palette->cd();
187 // palette
188 TPaveLabel *box1 = new TPaveLabel(2,2,98,16.3,"0","");
189 box1->SetTextFont(32);
190 box1->SetTextColor(1);
191 box1->SetTextSize(0.25);
192 box1->SetFillColor(10);
193 box1->Draw();
194 TPaveLabel *box2 = new TPaveLabel(2,18.3,98,32.66,"0-2","");
195 box2->SetTextFont(32);
196 box2->SetTextColor(1);
197 box2->SetTextSize(0.25);
198 box2->SetFillColor(38);
199 box2->Draw();
200 TPaveLabel *box3 = new TPaveLabel(2,34.66,98,48.96,"2-10","");
201 box3->SetTextFont(32);
202 box3->SetTextColor(1);
203 box3->SetTextSize(0.25);
204 box3->SetFillColor(4);
205 box3->Draw();
206 TPaveLabel *box4 = new TPaveLabel(2,50.96,98,65.26,"10-100","");
207 box4->SetTextFont(32);
208 box4->SetTextColor(1);
209 box4->SetTextSize(0.25);
210 box4->SetFillColor(3);
211 box4->Draw();
212 TPaveLabel *box5 = new TPaveLabel(2,67.26,98,81.56,"100-500","");
213 box5->SetTextFont(32);
214 box5->SetTextColor(1);
215 box5->SetTextSize(0.2);
216 box5->SetFillColor(2);
217 box5->Draw();
218 TPaveLabel *box6 = new TPaveLabel(2,83.56,98,97.86,">500","");
219 box6->SetTextFont(32);
220 box6->SetTextColor(1);
221 box6->SetTextSize(0.25);
222 box6->SetFillColor(6);
223 box6->Draw();
224 };
225 figura2->cd();
226 gStyle->SetOptDate(1);
227 if ( tyhist == "box" ) {
228 pd1->cd();
229 gStyle->SetOptStat(0);
230 Xview->SetXTitle("strip");
231 Xview->SetYTitle("X - plane");
232 Xview->GetYaxis()->SetTitleOffset(0.5);
233 Xview->SetFillColor(bgcolor);
234 Xview->Fill(1.,1.,1.);
235 Xview->Draw(tyhist);
236 pd1->Update();
237 pd2->cd();
238 gStyle->SetOptStat(0);
239 Yview->SetXTitle("strip");
240 Yview->SetYTitle("Y - plane");
241 Yview->GetYaxis()->SetTitleOffset(0.5);
242 Yview->SetFillColor(bgcolor);
243 Yview->Fill(1.,1.,1.);
244 Yview->Draw(tyhist);
245 pd2->Update();
246 };
247 //
248 // read from the header of the event the absolute time at which it was recorded
249 //
250 otr->GetEntry(i);
251 //
252 // run over views and planes
253 //
254 for (Int_t m = 0; m < 22; m++){
255 for (Int_t l = 0; l < 2; l++){
256 for (Int_t n = 0; n < 96; n++){
257 if ( calo->estrip[l][m][n] > 0.7 ) {
258 //
259 // OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course)
260 //
261 if ( tyhist == "box" ){
262 xview.str("");
263 xview << "x-view event " << n;
264 xview << " " << m;
265 xview << " " << l;
266 yview.str("");
267 yview << "y-view event " << n;
268 yview << " " << m;
269 yview << " " << l;
270 gDirectory->Delete(xview.str().c_str());
271 gDirectory->Delete(yview.str().c_str());
272 TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
273 TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
274 Int_t colo;
275 ColorMIP(calo->estrip[l][m][n],colo);
276 Xview->SetFillColor(colo);
277 Yview->SetFillColor(colo);
278 if ( l == 0 ) {
279 Xview->Fill(n,m,1.);
280 pd1->cd();
281 Xview->Draw("box same");
282 };
283 if ( l == 1 ) {
284 Yview->Fill(n,m,1.);
285 pd2->cd();
286 Yview->Draw("box same");
287 };
288 } else {
289 if ( l == 0 ) Xview->Fill(n,m,calo->estrip[l][m][n]);
290 if ( l == 1 ) Yview->Fill(n,m,calo->estrip[l][m][n]);
291 };
292 if ( calo->good[l][m][n] != 0 ) badstrip++;
293 };
294 };
295 };
296 };
297 //
298 figura2->cd();
299 t=new TLatex();
300 t->SetTextFont(32);
301 t->SetTextColor(8);
302 t->SetTextAlign(12);
303 t->SetTextSize(0.02);
304 Int_t qtot = (int)calo->qtot;
305 Int_t nstrip = (int)calo->nstrip;
306 stringa.str("");
307 stringa << "QTOT = " << qtot;
308 stringa << " NSTRIP = " << nstrip;
309 stringa << " Bad strips = " << badstrip;
310 stringa << " ";
311 t->DrawLatex(30.,2.,stringa.str().c_str());
312 figura2->Update();
313 if ( tyhist == "lego" ){
314 pd1->cd();
315 gStyle->SetOptStat(0);
316 Xview->SetXTitle("strip");
317 Xview->SetYTitle("X - plane");
318 Xview->GetXaxis()->SetTitleOffset(1.5);
319 Xview->GetYaxis()->SetTitleOffset(1.5);
320 Xview->SetZTitle("MIP");
321 Xview->Draw(tyhist);
322 pd1->Update();
323 pd2->cd();
324 gStyle->SetOptStat(0);
325 Yview->SetXTitle("strip");
326 Yview->SetYTitle("Y - plane");
327 Yview->GetXaxis()->SetTitleOffset(1.5);
328 Yview->GetYaxis()->SetTitleOffset(1.5);
329 Yview->SetZTitle("MIP");
330 Yview->Draw(tyhist);
331 pd2->Update();
332 };
333 pd1->Update();
334 pd2->Update();
335 figura2->Update();
336
337 //
338 // Interact with user: do you want to continue, exit or print the figure?
339 //
340 if ( i != maxevent ) {
341 TString figty = "matra";
342 doflag = 1;
343 Float_t lastevno = 0;
344 Float_t firstevno = 0;
345 Int_t jumpto = 0;
346 Int_t ifout = WhatToDo(i,doflag, jumpto,nevents,lastevno,firstevno,file,outDir,figty,*figura2);
347 if ( maxevent < i+1 ) {
348 maxevent = nevents;
349 printf("WARNING: you have chosen an event number out of the starting range.\n Range extended to %i\n\n",maxevent);
350 };
351 if ( ifout ) return;
352 } else {
353 const string fil = (const char*)filename;
354 Int_t posiz = fil.find("dw_");
355 if ( posiz == -1 ) posiz = fil.find("DW_");
356 Int_t posiz2 = posiz+13;
357 TString file2;
358 stringcopy(file2,filename,posiz,posiz2);
359 //
360 const char *figrec = file2;
361 const char *outdir = outDir;
362 stringstream figsave;
363 const char *format = saveas;
364 figsave.str("");
365 figsave << outdir << "/" ;
366 figsave << figrec << "_matra_";
367 figsave << (i+1) << ".";
368 figsave << format;
369 //
370 figura2->SaveAs(figsave.str().c_str());
371 };
372 if ( doflag == 2 && i == 0 ) {
373 printf("\n WARNING: Cannot go backward! Going forward. \n");
374 doflag = 1;
375 };
376 if ( doflag == 2 && i>0 ) i--;
377 if ( doflag == 1 ) i++;
378 };
379 //
380 // last warning (if the case)
381 //
382 figura2->Update();
383 printf("\n");
384 gSystem->ChangeDirectory(startingdir);
385 }

  ViewVC Help
Powered by ViewVC 1.1.23