/[PAMELA software]/calo/flight/CaloFranzini/src/CaloFranzini.cpp
ViewVC logotype

Contents of /calo/flight/CaloFranzini/src/CaloFranzini.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Thu Jan 3 10:02:28 2008 UTC (17 years ago) by mocchiut
Branch: MAIN
Changes since 1.4: +271 -25 lines
A lot of upgrades

1 /**
2 * \file CaloFranzini.cpp
3 * \author Emiliano Mocchiutti (2007/07/18)
4 */
5 //
6 // headers
7 //
8 #include <CaloFranzini.h>
9 //--------------------------------------
10 /**
11 * Default constructor
12 */
13 CaloFranzini::CaloFranzini(){
14 Clear();
15 }
16
17 CaloFranzini::CaloFranzini(PamLevel2 *l2p){
18 //
19 file = NULL;
20 brig = NULL;
21 brigm = NULL;
22 nbin = 0;
23 //
24 L2 = l2p;
25 //
26 if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
27 //
28 // Default variables
29 //
30 debug = false;
31 dolong = true;
32 dofull = false;
33 sntr = 0;
34 OBT = 0;
35 PKT = 0;
36 atime = 0;
37 //
38 crig = false;
39 sel = true;
40 cont = false;
41 N = 0;
42 NC = 43;
43 //
44 mask18b = -1;
45 //
46 Clear();
47 //
48 }
49
50 void CaloFranzini::Clear(){
51 //
52 longtzeta = 0.;
53 fulltzeta = 0.;
54 degfre = 0;
55 memset(estrip, 0, 2*22*96*sizeof(Float_t));
56 memset(qplane, 0, 43*sizeof(Float_t));
57 //
58 }
59
60 void CaloFranzini::Print(){
61 //
62 Process();
63 //
64 printf("========================================================================\n");
65 printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime);
66 printf(" debug [debug flag]:.. %i\n",debug);
67 printf(" degree of freedom :.. %i\n",this->GetDegreeOfFreedom());
68 printf(" longtzeta :.. %f\n",longtzeta);
69 printf(" longtzeta normalized :.. %f\n",this->GetNormLongTZeta());
70 // printf(" fulltzeta :.. %f\n",fulltzeta);
71 // printf(" longtzeta normalized :.. %f\n",this->GetNormFullTZeta());
72 printf("========================================================================\n");
73 //
74 }
75
76 void CaloFranzini::Delete(){
77 //
78 if ( file ) file->Close();
79 //
80 Clear();
81 //
82 }
83
84 void CaloFranzini::SetNoWpreSampler(Int_t n){
85 Int_t nc2 = NC/2;
86 if ( NC >= 37 ) nc2 = (NC+1)/2;
87 if ( nc2+n < 23 ){
88 N = n;
89 } else {
90 printf(" ERROR! Calorimeter is made of 22 W planes\n");
91 printf(" you are giving N presampler = %i and N calo = %i \n",n,NC);
92 printf(" WARNING: using default values NWpre = 0, NWcalo = 22\n");
93 NC = 43;
94 N = 0;
95 };
96 }
97
98 void CaloFranzini::SetNoWcalo(Int_t n){
99 if ( N+n < 23 ){
100 NC = n*2;
101 if ( NC >37 ) NC--;
102 } else {
103 printf(" ERROR! Calorimeter is made of 22 W planes\n");
104 printf(" you are giving N W presampler = %i and N W calo = %i \n",N,n);
105 printf(" WARNING: using default values NWpre = 0, NWcalo = 22\n");
106 NC = 43;
107 N = 0;
108 };
109 }
110
111 void CaloFranzini::Process(){
112 this->Process(0);
113 }
114
115 void CaloFranzini::Process(Int_t itr){
116 //
117 if ( !L2 ){
118 printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
119 printf(" ERROR: CaloFranzini variables _NOT_ filled \n");
120 return;
121 };
122 //
123 if ( !nbin || !file || !brig ){
124 printf(" ERROR: it seems covariance matrix file has not been opened (CaloFranzini::Open()) \n");
125 printf(" ERROR: CaloFranzini variables _NOT_ filled \n");
126 return;
127 };
128 //
129 Bool_t newentry = false;
130 //
131 if ( L2->IsORB() ){
132 if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || itr != sntr ){
133 newentry = true;
134 OBT = L2->GetOrbitalInfo()->OBT;
135 PKT = L2->GetOrbitalInfo()->pkt_num;
136 atime = L2->GetOrbitalInfo()->absTime;
137 sntr = itr;
138 };
139 } else {
140 newentry = true;
141 };
142 //
143 if ( !newentry ) return;
144 //
145 // Some variables
146 //
147 if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
148 //
149 this->Clear();
150 //
151 Float_t rig = L2->GetTrack(itr)->GetTrkTrack()->GetRigidity();
152 if ( crig ) rig = L2->GetCaloLevel2()->qtot/260.;
153 //
154 // Fill the estrip matrix
155 //
156 Int_t nplane = 0;
157 Int_t view = 0;
158 Int_t plane = 0;
159 Int_t strip = 0;
160 Float_t mip = 0.;
161 for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
162 //
163 mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
164 //
165 estrip[view][plane][strip] = mip;
166 //
167 nplane = 1 - view + 2 * (plane - N);
168 if ( nplane > (37-(2*N)) ) nplane--;
169 //
170 // if ( plane == (18+N) ) mip = 0.;
171 if ( nplane > -1 ) qplane[nplane] += mip;
172 //
173 };
174 //
175 //
176 //
177 if ( dolong ){
178 //
179 if ( cont ){
180 for (Int_t i=0; i<22; i++){
181 if ( i == (18+N) ){
182 mask18b = 1 + 2 * (i - N);
183 break;
184 };
185 };
186 };
187 //
188 if ( sel ){
189 for (Int_t i=0; i<22; i++){
190 if ( i == (18-N) ){
191 mask18b = 1 + 2 * (i - N);
192 break;
193 };
194 };
195 };
196 //
197 if ( mask18b == 37 ) mask18b = -1;
198 //
199 Int_t dgf = 43;
200 //
201 for (Int_t i=0; i < 22; i++){
202 if ( L2->GetTrack(itr)->GetCaloTrack()->tibar[i][1] < 0 ){
203 dgf = 2 * i;
204 break;
205 };
206 if ( L2->GetTrack(itr)->GetCaloTrack()->tibar[i][0] < 0 ){
207 dgf = 1 + 2 * i;
208 break;
209 };
210 };
211 //
212 if ( dgf < 43 && dgf > 37 ) dgf--;
213 //
214 degfre = TMath::Min(dgf,NC);
215 //
216 Float_t longzdiag = 0.;
217 Float_t longzout = 0.;
218 //
219 if ( degfre > 0 ){
220 for (Int_t i = 0; i < degfre; i++){
221 if ( i != mask18b ){
222 for (Int_t j = 0; j < degfre; j++){
223 if ( j != mask18b ){
224 if ( i == j ){
225 longzdiag += (qplane[i]-this->GetAverageAt(i,rig)) * this->GetHmatrixAt(i,j,rig) * (qplane[j]-this->GetAverageAt(j,rig));
226 if ( debug ) printf(" %i %i %f %f %f %f %f\n",i,j,qplane[i],this->GetAverageAt(i,rig),this->GetHmatrixAt(i,j,rig),qplane[j],this->GetAverageAt(j,rig));
227 } else {
228 longzout += (qplane[i]-this->GetAverageAt(i,rig)) * this->GetHmatrixAt(i,j,rig) * (qplane[j]-this->GetAverageAt(j,rig));
229 if ( debug && i == (j+1) ) printf(" %i %i %f %f %f %f %f\n",i,j,qplane[i],this->GetAverageAt(i,rig),this->GetHmatrixAt(i,j,rig),qplane[j],this->GetAverageAt(j,rig));
230 };
231 longtzeta += (qplane[i]-this->GetAverageAt(i,rig)) * this->GetHmatrixAt(i,j,rig) * (qplane[j]-this->GetAverageAt(j,rig));
232 };
233 };
234 };
235 };
236 if ( debug ) printf(" diagonal total %f out of diagonal total %f \n",longzdiag,longzout);
237 };
238 };
239 if ( dofull ){
240 printf(" ERROR: NOT IMPLEMENTED YET\n");
241 printf(" ERROR: CaloFranzini variables _NOT_ filled \n");
242 };
243 //
244 // if ( debug ) this->Print();
245 if ( debug ) printf(" exit \n");
246 }
247
248
249 Float_t CaloFranzini::GetNormLongTZeta(){
250 Process();
251 Float_t normz = 0.;
252 if ( degfre > 0 ) normz = longtzeta/(Float_t)degfre;
253 return normz;
254 }
255
256 Float_t CaloFranzini::GetNormFullTZeta(){
257 Process();
258 Float_t normz = 0.;
259 if ( degfre > 0 ) normz = fulltzeta/(Float_t)degfre;
260 return normz;
261 }
262
263 Bool_t CaloFranzini::CreateMatrixFile(TString matrixfile){
264 //
265 file = new TFile(matrixfile.Data(),"READ");
266 //
267 if ( !file || file->IsZombie() ){
268 file = new TFile(matrixfile.Data(),"RECREATE");
269 printf(" Create file %s \n",file->GetName());
270 } else {
271 printf(" ERROR: file %s already existing!\n Choose another name or delete the old file\n",matrixfile.Data());
272 return(false);
273 };
274 //
275 return(true);
276 //
277 }
278
279 Bool_t CaloFranzini::UpdateMatrixFile(TString matrixfile){
280 //
281 file = new TFile(matrixfile.Data(),"UPDATE");
282 //
283 if ( !file || file->IsZombie() ){
284 printf(" ERROR: file %s already existing!\n Choose another name or delete the old file\n",matrixfile.Data());
285 return(false);
286 };
287 //
288 return(true);
289 //
290 }
291
292 void CaloFranzini::WriteNumBin(Int_t numbin){
293 file->cd();
294 TArrayI nbi(1, &numbin);
295 file->WriteObject(&nbi, "nbinenergy");
296 }
297
298 void CaloFranzini::WriteRigBin(TArrayF *rigbin){
299 file->cd();
300 // rigbin->Write("binrig");
301 file->WriteObject(&(*rigbin), "binrig");
302 }
303
304 void CaloFranzini::WriteLongMean(TArrayF *qpl, Int_t bin){
305 file->cd();
306 TString name = Form("qplmeann%i",bin);
307 file->WriteObject(&(*qpl),name.Data());
308 }
309
310 void CaloFranzini::WriteFullMean(TMatrixD *qpl, Int_t bin){
311 file->cd();
312 TString name = Form("fqplmeann%i",bin);
313 file->WriteObject(&(*qpl),name.Data());
314 }
315
316 void CaloFranzini::WriteInvertedLongMatrix(TMatrixD mat, Int_t bin){
317 file->cd();
318 TString name = Form("matrixn%i",bin);
319 // mat.Write(name.Data());
320 file->WriteObject(&mat,name.Data());
321 }
322
323 void CaloFranzini::WriteInvertedFullMatrix(TMatrixF mat, Int_t bin){
324 file->cd();
325 TString name = Form("fmatrixn%i",bin);
326 // mat.Write(name.Data());
327 file->WriteObject(&mat,name.Data());
328 }
329
330 void CaloFranzini::WriteLongMatrix(TMatrixD *mat, Int_t bin){
331 file->cd();
332 TString name = Form("origmatrixn%i",bin);
333 // mat.Write(name.Data());
334 file->WriteObject(&(*mat),name.Data());
335 }
336
337 void CaloFranzini::WriteFullMatrix(TMatrixF *mat, Int_t bin){
338 file->cd();
339 TString name = Form("origfmatrixn%i",bin);
340 // mat.Write(name.Data());
341 file->WriteObject(&(*mat),name.Data());
342 }
343
344 void CaloFranzini::CloseMatrixFile(){
345 file->cd();
346 file->Close();
347 }
348
349
350 Bool_t CaloFranzini::Open(TString matrixfile){
351 //
352 // find matrix file
353 //
354 if ( !strcmp(matrixfile.Data(),"") ){
355 if (dolong) matrixfile = (TString)gSystem->ExpandPathName("$PAM_CALIB")+"/cal-param/covmatrix_longel.root";
356 if (dofull) matrixfile = (TString)gSystem->ExpandPathName("$PAM_CALIB")+"/cal-param/covmatrix_fullel.root";
357 };
358 //
359 file = new TFile(matrixfile.Data(),"READ");
360 //
361 if ( !file || file->IsZombie() ){
362 printf(" ERROR: cannot open file %s \n",matrixfile.Data());
363 return(false);
364 };
365 //
366 if ( !this->LoadBin() ){
367 printf(" %s \n",matrixfile.Data());
368 return(false);
369 };
370 //
371 if ( dolong ){
372 if ( !this->LoadLong() ){
373 printf(" %s \n",matrixfile.Data());
374 return(false);
375 };
376 //
377 if ( !this->LoadMatrices() ){
378 printf(" %s \n",matrixfile.Data());
379 return(false);
380 };
381 };
382 //
383 if ( dofull ){
384 if ( !this->LoadFull() ){
385 printf(" %s \n",matrixfile.Data());
386 return(false);
387 };
388 //
389 if ( !this->LoadFullMatrices() ){
390 printf(" %s \n",matrixfile.Data());
391 return(false);
392 };
393 };
394 //
395 //
396 return(true);
397 //
398 }
399
400 Bool_t CaloFranzini::LoadBin(){
401 //
402 TArrayI *numbin = (TArrayI*)file->Get("nbinenergy");
403 if ( !numbin ){
404 printf(" ERROR: cannot read number of bins from file ");
405 return(false);
406 };
407 nbin = (Int_t)numbin->At(0);
408 if ( nbin <= 0 ){
409 printf(" ERROR: cannot work with 0 energy bins from file ");
410 return(false);
411 };
412 //
413 brig = (TArrayF*)file->Get("binrig");
414 if ( !brig ){
415 printf(" ERROR: cannot read rigidity binning from file ");
416 return(false);
417 };
418 //
419 brigm=(TArrayF*)file->Get("binrigmean");
420 if ( !brigm ){
421 printf(" ERROR: cannot read mean rigidity binning from file ");
422 return(false);
423 };
424 //
425 return(true);
426 }
427
428 Bool_t CaloFranzini::LoadLong(){
429 //
430 for (Int_t i=0;i<17;i++){
431 TString name = Form("qplmeann%i",i);
432 qplmean[i] = (TArrayF*)file->Get(name.Data());
433 if ( !qplmean[i] ){
434 printf(" ERROR: cannot read average from file ");
435 return(false);
436 };
437 };
438 //
439 return(true);
440 }
441
442 Bool_t CaloFranzini::LoadFull(){
443 //
444 for (Int_t i=0;i<17;i++){
445 TString name = Form("fqplmeann%i",i);
446 fqplmean[i] = (TMatrixD*)file->Get(name.Data());
447 if ( !fqplmean[i] ){
448 printf(" ERROR: cannot read average from file ");
449 return(false);
450 };
451 };
452 //
453 return(true);
454 }
455
456 Bool_t CaloFranzini::LoadMatrices(){
457 //
458 for (Int_t i=0;i<17;i++){
459 TString name1 = Form("matrixn%i",i);
460 hmat[i] = (TMatrixD*)file->Get(name1.Data());
461 };
462 //
463 return(true);
464 }
465
466 Bool_t CaloFranzini::LoadFullMatrices(){
467 //
468 for (Int_t i=0;i<17;i++){
469 TString name1 = Form("fmatrixn%i",i);
470 hfmat[i] = (TMatrixF*)file->Get(name1.Data());
471 };
472 //
473 return(true);
474 }
475
476 TMatrixD *CaloFranzini::LoadCovarianceMatrix(Float_t rig){
477 //
478 Int_t mv = 0;
479 for (Int_t i = 0; i<nbin-1; i++){
480 if ( rig>=brig->At(i) && rig < brig->At(i+1) ){
481 mv = i;
482 break;
483 };
484 };
485 if ( rig < brig->At(0) ){
486 printf(" WARNING: Event with rigidity lower than the first covariance matrix bin (rig = %f, lower limit = %f)\n",rig,brig->At(0));
487 mv = 0;
488 };
489 if ( rig >= brig->At(nbin-1) ){
490 printf(" WARNING: Event with rigidity higher than the last covariance matrix bin (rig = %f, upper limit = %f)\n",rig,brig->At(nbin-1));
491 mv = nbin-2;
492 };
493 //
494 return(hmat[mv]);
495 //
496 }
497
498
499 TArrayF *CaloFranzini::LoadLongAverage(Float_t rig){
500 //
501 Int_t mv=0;
502 for (Int_t i = 0; i<nbin-1; i++){
503 if ( rig>=brig->At(i) && rig < brig->At(i+1) ){
504 mv = i;
505 break;
506 };
507 };
508 if ( rig < brig->At(0) ){
509 printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brig->At(0));
510 mv = 0;
511 };
512 if ( rig >= brig->At(nbin-1) ){
513 printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brig->At(nbin-1));
514 mv=nbin-2;
515 };
516 //
517 return(qplmean[mv]);
518 //
519 }
520
521 Float_t CaloFranzini::GetAverageAt(Int_t plane, Float_t rig){
522 //
523 Int_t therigb = 0;
524 for (Int_t i = 0; i<nbin-2; i++){
525 if ( rig>=brigm->At(i) && rig < brigm->At(i+1) ){
526 therigb = i;
527 break;
528 };
529 };
530 //
531 Float_t minrig;
532 Float_t maxrig;
533 //
534 //
535 if ( rig < brigm->At(0) ){
536 if ( rig < brig->At(0) ){
537 // printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brigm->At(0));
538 };
539 therigb = 0;
540 };
541 if ( rig >= brigm->At(nbin-2) ){
542 if ( rig >= brig->At(nbin-2) ) {
543 // printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brigm->At(nbin-2));
544 };
545 therigb = nbin - 3;
546 };
547 //
548 minrig = brigm->At(therigb);
549 maxrig = brigm->At(therigb+1);
550 //
551 Float_t minene = (*qplmean[therigb])[plane];
552 Float_t maxene = (*qplmean[therigb+1])[plane];
553 //
554 if ( maxrig == minrig ){
555 printf("Unrecoverable ERROR! Matrix will be screwed up... \n");
556 return(0.);
557 };
558 Float_t b = log(maxene/minene)/(maxrig-minrig);
559 Float_t a = minene/exp(minrig*b);
560 Float_t ave = a*exp(b*rig);
561 //
562 return(ave);
563 //
564 }
565 Float_t CaloFranzini::GetFullAverageAt(Int_t plane, Int_t strip, Float_t rig){
566 //
567 Int_t therigb = 0;
568 for (Int_t i = 0; i<nbin-2; i++){
569 if ( rig>=brigm->At(i) && rig < brigm->At(i+1) ){
570 therigb = i;
571 break;
572 };
573 };
574 //
575 Float_t minrig;
576 Float_t maxrig;
577 //
578 //
579 if ( rig < brigm->At(0) ){
580 if ( rig < brig->At(0) ){
581 // printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brigm->At(0));
582 };
583 therigb = 0;
584 };
585 if ( rig >= brigm->At(nbin-2) ){
586 if ( rig >= brig->At(nbin-2) ) {
587 // printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brigm->At(nbin-2));
588 };
589 therigb = nbin - 3;
590 };
591 //
592 minrig = brigm->At(therigb);
593 maxrig = brigm->At(therigb+1);
594 //
595 Float_t minene = (*fqplmean[therigb])[plane][strip];
596 Float_t maxene = (*fqplmean[therigb+1])[plane][strip];
597 //
598 if ( maxrig == minrig ){
599 printf("Unrecoverable ERROR! Matrix will be screwed up... \n");
600 return(0.);
601 };
602 Float_t b = log(maxene/minene)/(maxrig-minrig);
603 Float_t a = minene/exp(minrig*b);
604 Float_t ave = a*exp(b*rig);
605 //
606 return(ave);
607 //
608 }
609
610 Float_t CaloFranzini::GetHmatrixAt(Int_t iindex, Int_t jindex, Float_t rig){
611 Int_t therigb = 0;
612 for (Int_t i = 0; i<nbin-2; i++){
613 if ( rig>=brigm->At(i) && rig < brigm->At(i+1) ){
614 therigb = i;
615 break;
616 };
617 };
618 //
619 Float_t minrig;
620 Float_t maxrig;
621 //
622 if ( rig < brigm->At(0) ){
623 if ( rig < brig->At(0) ){
624 // printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brigm->At(0));
625 };
626 therigb = 0;
627 };
628 // if ( rig >= brigm->At(nbin-4) ){ // -2
629 if ( rig >= brigm->At(nbin-2) ){
630 if ( rig >= brig->At(nbin-2) ) {
631 // printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brigm->At(nbin-2));
632 };
633 // therigb = nbin - 5;// -3
634 therigb = nbin - 3;
635 };
636 //
637 if ( therigb < 2 ) therigb = 2;
638 minrig = brigm->At(therigb);
639 maxrig = brigm->At(therigb+1);
640 // printf(" therigb %i minrig %f maxrig %f rig %f %i i %i j \n",therigb,minrig,maxrig,rig,iindex,jindex);
641 //
642 Float_t minene = (*hmat[therigb])[iindex][jindex];
643 Float_t maxene = (*hmat[therigb+1])[iindex][jindex];
644 // printf(" therigb %i minrig %f maxrig %f minene %f maxene %f a %f b %f rig %f ave %f \n",therigb,minrig,maxrig,minene,maxene,a,b,rig,ave);
645 //
646 // Float_t a = 0.;
647 // Float_t b = 0.;
648 // Float_t ave = 0.;
649 // if ( minene == 0. ){
650 //
651 // } else {
652 // b = log(maxene/minene)/(maxrig-minrig);
653 // a = minene/exp(minrig*b);
654 // ave = a*exp(b*rig);
655 // };
656 //
657 Float_t m = (maxene-minene)/(maxrig-minrig);
658 Float_t q = minene - m * minrig;
659 Float_t ave = rig * m + q;
660 if ( debug ) printf(" therigb %i minrig %f maxrig %f minene %f maxene %f a %f b %f rig %f ave %f \n",therigb,minrig,maxrig,minene,maxene,m,q,rig,ave);
661 //
662 //
663 return(ave);
664 //
665 }
666
667 Float_t CaloFranzini::GetFullHmatrixAt(Int_t iindex, Int_t jindex, Float_t rig){
668 Int_t therigb = 0;
669 for (Int_t i = 0; i<nbin-2; i++){
670 if ( rig>=brigm->At(i) && rig < brigm->At(i+1) ){
671 therigb = i;
672 break;
673 };
674 };
675 //
676 Float_t minrig;
677 Float_t maxrig;
678 //
679 if ( rig < brigm->At(0) ){
680 if ( rig < brig->At(0) ){
681 // printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brigm->At(0));
682 };
683 therigb = 0;
684 };
685 // if ( rig >= brigm->At(nbin-4) ){ // -2
686 if ( rig >= brigm->At(nbin-2) ){
687 if ( rig >= brig->At(nbin-2) ) {
688 // printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brigm->At(nbin-2));
689 };
690 // therigb = nbin - 5;// -3
691 therigb = nbin - 3;
692 };
693 //
694 if ( therigb < 2 ) therigb = 2;
695 minrig = brigm->At(therigb);
696 maxrig = brigm->At(therigb+1);
697 // printf(" therigb %i minrig %f maxrig %f rig %f %i i %i j \n",therigb,minrig,maxrig,rig,iindex,jindex);
698 //
699 Float_t minene = (*hfmat[therigb])[iindex][jindex];
700 Float_t maxene = (*hfmat[therigb+1])[iindex][jindex];
701 // printf(" therigb %i minrig %f maxrig %f minene %f maxene %f a %f b %f rig %f ave %f \n",therigb,minrig,maxrig,minene,maxene,a,b,rig,ave);
702 //
703 // Float_t a = 0.;
704 // Float_t b = 0.;
705 // Float_t ave = 0.;
706 // if ( minene == 0. ){
707 //
708 // } else {
709 // b = log(maxene/minene)/(maxrig-minrig);
710 // a = minene/exp(minrig*b);
711 // ave = a*exp(b*rig);
712 // };
713 //
714 Float_t m = (maxene-minene)/(maxrig-minrig);
715 Float_t q = minene - m * minrig;
716 Float_t ave = rig * m + q;
717 if ( debug ) printf(" therigb %i minrig %f maxrig %f minene %f maxene %f a %f b %f rig %f ave %f \n",therigb,minrig,maxrig,minene,maxene,m,q,rig,ave);
718 //
719 //
720 return(ave);
721 //
722 }
723
724 void CaloFranzini::DrawLongAverage(Float_t rig){
725 //
726 TArrayF *ll = this->LoadLongAverage(rig);
727 //
728 gStyle->SetLabelSize(0.04);
729 gStyle->SetNdivisions(510,"XY");
730 //
731 TString hid = Form("cfralongvyvx");
732 TCanvas *tcf = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid));
733 if ( tcf ){
734 tcf->cd();
735 } else {
736 tcf = new TCanvas(hid,hid);
737 };
738 //
739 TString thid = Form("hfralongvyvx");
740 TH1F *thf = dynamic_cast<TH1F*>(gDirectory->FindObject(thid));
741 if ( thf ) thf->Delete();
742 thf = new TH1F(thid,thid,44,-0.5,43.5);
743 tcf->cd();
744 Float_t qpl[43];
745 for (Int_t st=0;st<43;st++){
746 qpl[st] = ll->At(st);
747 printf("st %i qpl %f\n",st,qpl[st]);
748 };
749 for (Int_t st=0;st<44;st++){
750 if ( st == 37 ){
751 thf->Fill(st,0.);
752 } else {
753 Int_t ss = st;
754 if ( st > 37 ) ss--;
755 thf->Fill(st,qpl[ss]);
756 };
757 };
758 thf->Draw();
759 tcf->Modified();
760 tcf->Update();
761 //
762 gStyle->SetLabelSize(0);
763 gStyle->SetNdivisions(1,"XY");
764 //
765 };
766
767 void CaloFranzini::DrawLongAverage(Int_t bin){
768 //
769 TArrayF *ll = this->LoadLongAverage(brigm->At(bin));
770 //
771 gStyle->SetLabelSize(0.04);
772 gStyle->SetNdivisions(510,"XY");
773 //
774 TString hid = Form("cfralongvyvx");
775 TCanvas *tcf = dynamic_cast<TCanvas*>(gDirectory->FindObject(hid));
776 if ( tcf ){
777 tcf->cd();
778 } else {
779 tcf = new TCanvas(hid,hid);
780 };
781 //
782 TString thid = Form("hfralongvyvx");
783 TH1F *thf = dynamic_cast<TH1F*>(gDirectory->FindObject(thid));
784 if ( thf ) thf->Delete();
785 thf = new TH1F(thid,thid,44,-0.5,43.5);
786 tcf->cd();
787 Float_t qpl[43];
788 for (Int_t st=0;st<43;st++){
789 qpl[st] = ll->At(st);
790 printf("st %i qpl %f\n",st,qpl[st]);
791 };
792 for (Int_t st=0;st<44;st++){
793 if ( st == 37 ){
794 thf->Fill(st,0.);
795 } else {
796 Int_t ss = st;
797 if ( st > 37 ) ss--;
798 thf->Fill(st,qpl[ss]);
799 };
800 };
801 thf->Draw();
802 tcf->Modified();
803 tcf->Update();
804 //
805 gStyle->SetLabelSize(0);
806 gStyle->SetNdivisions(1,"XY");
807 //
808 };

  ViewVC Help
Powered by ViewVC 1.1.23