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

Annotation of /calo/flight/FUTILITIES/macros/FCaloCHECKCRC.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Fri Jun 30 12:08:14 2006 UTC (18 years, 5 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r03, HEAD
Added FCaloCHECKCRC utility

1 mocchiut 1.1 //
2     //
3     //
4     //
5     #include <fstream>
6     #include <sstream>
7     #include <TTree.h>
8     #include <TBranch.h>
9     #include <TClassEdit.h>
10     #include <TObject.h>
11     #include <TList.h>
12     #include <TSystem.h>
13     #include <TSystemDirectory.h>
14     #include <TString.h>
15     #include <TFile.h>
16     #include <TClass.h>
17     #include <TCanvas.h>
18     #include <TH1.h>
19     #include <TH1F.h>
20     #include <TH2D.h>
21     #include <TLatex.h>
22     #include <TPad.h>
23     #include <TPaveLabel.h>
24     #include <TChain.h>
25     #include <PamelaRun.h>
26     #include <physics/calorimeter/CalorimeterEvent.h>
27     #include <CalibCalPedEvent.h>
28     //
29    
30     short int FCaloCHECKCRC(TString filename1, TString filename2){
31     //
32     // open first file
33     //
34     TFile *File1 = new TFile(filename1.Data());
35     TTree *otr1 = (TTree*)File1->Get("Physics");
36     TBranch *l0head1 = 0;
37     TBranch *l0calo1 = 0;
38     //
39     pamela::calorimeter::CalorimeterEvent *de1 = 0;
40     pamela::PscuHeader *ph1 = 0;
41     pamela::EventHeader *eh1 = 0;
42     //
43     l0head1 = otr1->GetBranch("Header");
44     l0calo1 = otr1->GetBranch("Calorimeter");
45     //
46     otr1->SetBranchAddress("Calorimeter", &de1);
47     otr1->SetBranchAddress("Header", &eh1);
48     //
49     // open second file
50     //
51     TFile *File2 = new TFile(filename2.Data());
52     TTree *otr2 = (TTree*)File2->Get("Physics");
53     TBranch *l0head2 = 0;
54     TBranch *l0calo2 = 0;
55     //
56     pamela::calorimeter::CalorimeterEvent *de2 = 0;
57     pamela::PscuHeader *ph2 = 0;
58     pamela::EventHeader *eh2 = 0;
59     //
60     l0head2 = otr2->GetBranch("Header");
61     l0calo2 = otr2->GetBranch("Calorimeter");
62     //
63     otr2->SetBranchAddress("Calorimeter", &de2);
64     otr2->SetBranchAddress("Header", &eh2);
65     //
66     // Define variables
67     //
68     Long64_t nevents1 = otr1->GetEntries();
69     Long64_t nevents2 = otr2->GetEntries();
70     if ( nevents1 < 1 ) {
71     printf("The file %s is empty!\n",filename1.Data());
72     return(1);
73     };
74     if ( nevents2 < 1 ) {
75     printf("The file %s is empty!\n",filename2.Data());
76     return(2);
77     };
78     //
79     printf("\n Processed events: \n\n");
80     //
81     Int_t c1 = 0;
82     Int_t c2 = 0;
83     Int_t ecount1 = 0;
84     Int_t ecount2 = 0;
85     Int_t etime1 = 0;
86     Int_t etime2 = 0;
87     //
88     Int_t frstbad[4];
89     Int_t scndbad[4];
90     Int_t crcfrstbad[4];
91     Int_t crcscndbad[4];
92     Int_t crcbothbad[4];
93     Int_t frstbadscndgood[4];
94     Int_t frstgoodscndbad[4];
95     Int_t crcfrstbadscndgood[4];
96     Int_t crcfrstgoodscndbad[4];
97     Int_t bothbad[4];
98     Int_t bothgood[4];
99     Int_t samecheck[4];
100     Int_t differentcheck[4];
101     Int_t samecrc[4];
102     Int_t differentcrc[4];
103     //
104     for ( Int_t s=0; s<4; s++){
105     frstbad[s] = 0;
106     scndbad[s] = 0;
107     crcfrstbad[s] = 0;
108     crcscndbad[s] = 0;
109     crcbothbad[s] = 0;
110     frstbadscndgood[s] = 0;
111     frstgoodscndbad[s] = 0;
112     crcfrstbadscndgood[s] = 0;
113     crcfrstgoodscndbad[s] = 0;
114     bothbad[s] = 0;
115     bothgood[s] = 0;
116     samecheck[s] = 0;
117     differentcheck[s] = 0;
118     samecrc[s] = 0;
119     differentcrc[s] = 0;
120     };
121     //
122     // for (Int_t i = 0; i < 3000; i++){
123     //
124     for (Int_t i = 0; i < max(nevents1,nevents2); i++){
125     //
126     if ( i%1000 == 0 && i > 0 ) printf(" %iK \n",i/1000);
127     //
128     // read from the header of the event the absolute time at which it was recorded
129     //
130     if ( c1 < nevents1 ){
131     l0head1->GetEntry(c1);
132     ph1 = eh1->GetPscuHeader();
133     etime1 = ph1->GetOrbitalTime();
134     ecount1 = ph1->GetCounter();
135     };
136     //
137     if ( c2 < nevents2 ){
138     l0head2->GetEntry(c2);
139     ph2 = eh2->GetPscuHeader();
140     etime2 = ph2->GetOrbitalTime();
141     ecount2 = ph2->GetCounter();
142     };
143     //
144     if ( etime2 == etime1 && ecount2 == ecount1 ){
145     if ( c1 < nevents1 ) l0calo1->GetEntry(c1);
146     if ( c2 < nevents2 ) l0calo2->GetEntry(c2);
147     //
148     //
149     //
150     for ( Int_t s=0; s<4; s++){
151     //
152     // sum of frstbadscndgood e frstgoodscndbad gives us how many GOOD events we can have merging the two files (not only CRC errors)
153     //
154     if ( de1->perror[s] != 0 ) frstbad[s]++;
155     if ( de2->perror[s] != 0 ) scndbad[s]++;
156     if ( de1->perror[s] == 132 ) crcfrstbad[s]++;
157     if ( de2->perror[s] == 132 ) crcscndbad[s]++;
158     if ( de1->perror[s] != 0 && de2->perror[2] == 0 ) frstbadscndgood[s]++;
159     if ( de1->perror[s] == 0 && de2->perror[2] != 0 ) frstgoodscndbad[s]++;
160     if ( de1->perror[s] != 0 && de2->perror[2] != 0 ) bothbad[s]++;
161     if ( de1->perror[s] == 0 && de2->perror[2] == 0 ) bothgood[s]++;
162     //
163     if ( de1->perror[s] == 132 && de2->perror[2] == 0 ) crcfrstbadscndgood[s]++;
164     if ( de1->perror[s] == 0 && de2->perror[2] == 132 ) crcfrstgoodscndbad[s]++;
165     if ( de1->perror[s] == 132 && de2->perror[2] == 132 ){
166     crcbothbad[s]++;
167     if ( de1->calselftrig[0] == de2->calselftrig[0] ) samecheck[s]++;
168     if ( de1->calselftrig[0] != de2->calselftrig[0] ) differentcheck[s]++;
169     if ( de1->calselftrig[1] == de2->calselftrig[1] ) samecrc[s]++;
170     if ( de1->calselftrig[1] != de2->calselftrig[1] ) differentcrc[s]++;
171     };
172     };
173     //
174     c1++;
175     c2++;
176     } else {
177     if ( etime2 > etime1 || ecount2 > ecount1 ){
178     if ( c1 < nevents1 ){
179     l0calo1->GetEntry(c1);
180     for ( Int_t s=0; s<4; s++){
181     if ( de1->perror[s] != 0 ) frstbad[s]++;
182     if ( de1->perror[s] != 0 ) crcfrstbad[s]++;
183     if ( de1->perror[s] == 0 ) frstgoodscndbad[s]++;
184     if ( de1->perror[s] == 132 ){
185     crcbothbad[s]++;
186     differentcheck[s]++;
187     differentcrc[s]++;
188     };
189     };
190     };
191     c1++;
192     };
193     if ( etime1 > etime2 || ecount1 > ecount2 ){
194     if ( c2 < nevents2 ){
195     l0calo2->GetEntry(c2);
196     for ( Int_t s=0; s<4; s++){
197     if ( de2->perror[s] != 0 ) scndbad[s]++;
198     if ( de2->perror[s] != 0 ) crcscndbad[s]++;
199     if ( de2->perror[s] == 0 ) frstbadscndgood[s]++;
200     if ( de2->perror[s] == 132 ){
201     crcbothbad[s]++;
202     differentcheck[s]++;
203     differentcrc[s]++;
204     };
205     };
206     };
207     c2++;
208     };
209     };
210     };
211     //
212     printf("\n\n");
213     printf("##############################################################################\n");
214     printf(" File 1: %s \n",filename1.Data());
215     printf(" File 2: %s \n",filename2.Data());
216     printf("##############################################################################\n");
217     for ( Int_t s=0; s<4; s++){
218     printf("################################# SECTION %i ##################################\n",s);
219     printf(" File 1: number of events........... = %i \n",(int)nevents1);
220     printf(" : number of errors........... = %i \n",frstbad[s]);
221     printf(" : number of CRC errors....... = %i \n",crcfrstbad[s]);
222     printf(" File 2: number of events........... = %i \n",(int)nevents2);
223     printf(" : number of errors........... = %i \n",scndbad[s]);
224     printf(" : number of CRC errors....... = %i \n",crcscndbad[s]);
225     printf(" Events bad in both files........... = %i \n",bothbad[s]);
226     printf(" Events good in both files.......... = %i \n",bothgood[s]);
227     printf(" Events good in the first and bad in the second file.............. = %i \n",frstgoodscndbad[s]);
228     printf(" Events bad in the first and good in the second file.............. = %i \n",frstbadscndgood[s]);
229     printf(" Events good in the first and with CRC error in the second file... = %i \n",crcfrstgoodscndbad[s]);
230     printf(" Events with CRC error in the first and good in the second file... = %i \n",crcfrstbadscndgood[s]);
231     printf(" Events with CRC error in both files.............................. = %i \n",crcbothbad[s]);
232     printf(" Events with CRC error in both files and same transmitted CRC..... = %i \n",samecrc[s]);
233     printf(" Events with CRC error in both files and different transmitted CRC = %i \n",differentcrc[s]);
234     printf(" Events with CRC error in both files and same calculated CRC...... = %i \n",samecheck[s]);
235     printf(" Events with CRC error in both files and different calculated CRC. = %i \n",differentcheck[s]);
236     printf(" Merging the two files you will have %i good events \n",bothgood[s]+frstgoodscndbad[s]+frstbadscndgood[s]);
237     printf("##############################################################################\n");
238     };
239     printf("\n\n");
240     //
241     return(0);
242     //
243     }
244    
245    
246    

  ViewVC Help
Powered by ViewVC 1.1.23