AMSDST
myEvent.cxx
Go to the documentation of this file.
1 // Authors: M.Duranti - INFN di Perugia
2 #include "myEvent.h"
3 #include "debug.h"
4 #include <TClass.h>
5 #include <iostream>
6 #include <config.hxx>
7 #include "myChain.h"
8 
9 using namespace std;
10 
11 //--------------------------------------------------------------------
12 
14 
15 //--------------------------------------------------------------------
16 
18 section_t gsection;
19 
20 Double_t myEvent::zlay[9];
21 
22 unsigned int TimePrevSlow = 0;
23 unsigned int TimePrevISS = 0;
24 
26  mm(nullptr),ms(nullptr),RTI(nullptr)
27 {
28 #ifdef PDEBUG
29  printf("In myEvent::myEvent\n");
30 #endif
31  init();
32  PRINTDEBUG;
33  if (ptr) {
34  printf("%s::%s was already existing (%p)... Substituting it (with %p)!\n", ptr->ClassName(), ptr->GetName(), ptr, this);
35  }
36  else printf("Object myEvent (%p) created...\n", this);//only for debug
37  ptr = this;
38 }
39 
40 
42 
43  kMC=orig.kMC;
44 
45  if(orig.mm) mm = new myMC(*orig.mm);
46  else mm=0;
47 
48  if(orig.ms) ms = new myStatus(*orig.ms);
49  else ms=0;
50 
51  fHeader = myHeader(orig.fHeader);
52 
53  us1=0;
54 
55  vmp.clear();
56  for (int ii=0; ii<(int)(vmp.size()); ii++) {
57  vmp.push_back(orig.vmp[ii]);
58  }
59 
60  vmt.clear();
61  for (int ii=0; ii<(int)(vmt.size()); ii++) {
62  vmt.push_back(orig.vmt[ii]);
63  }
64  vme.clear();
65  for (int ii=0; ii<(int)(vme.size()); ii++) {
66  vme.push_back(orig.vme[ii]);
67  }
68  vmu.clear();
69  for (int ii=0; ii<(int)(vmu.size()); ii++) {
70  vmu.push_back(orig.vmu[ii]);
71  }
72  vmb.clear();
73  for (int ii=0; ii<(int)(vmb.size()); ii++) {
74  vmb.push_back(orig.vmb[ii]);
75  }
76  vmbh.clear();
77  for (int ii=0; ii<(int)(vmbh.size()); ii++) {
78  vmbh.push_back(orig.vmbh[ii]);
79  }
80  vmr.clear();
81  for (int ii=0; ii<(int)(vmr.size()); ii++) {
82  vmr.push_back(orig.vmr[ii]);
83  }
84 
85  vmup.clear();
86  for (int ii=0; ii<(int)(vmup.size()); ii++) {
87  vmup.push_back(orig.vmup[ii]);
88  }
89  /*
90  vmukp.clear();
91  for (int ii=0; ii<(int)(vmukp.size()); ii++) {
92  vmukp.push_back(orig.vmukp[ii]);
93  }
94  */
95  vmuktp = orig.vmuktp;
96  vmukup = orig.vmukup;
97 
98  vmuqtp.clear();
99  for (int ii=0; ii<(int)(vmuqtp.size()); ii++) {
100  vmuqtp.push_back(orig.vmuqtp[ii]);
101  }
102  vmtp.clear();
103  for (int ii=0; ii<(int)(vmtp.size()); ii++) {
104  vmtp.push_back(orig.vmtp[ii]);
105  }
106  vmep.clear();
107  for (int ii=0; ii<(int)(vmep.size()); ii++) {
108  vmep.push_back(orig.vmep[ii]);
109  }
110  vmrp.clear();
111  for (int ii=0; ii<(int)(vmrp.size()); ii++) {
112  vmrp.push_back(orig.vmrp[ii]);
113  }
114  vmbp.clear();
115  for (int ii=0; ii<(int)(vmbp.size()); ii++) {
116  vmbp.push_back(orig.vmbp[ii]);
117  }
118  vmbhp.clear();
119  for (int ii=0; ii<(int)(vmbhp.size()); ii++) {
120  vmbhp.push_back(orig.vmbhp[ii]);
121  }
122 
123  // fNmyParticle =orig.fNmyParticle;
124 
125  // fNmyTrTrack =orig.fNmyTrTrack;
126  // fNmyEcalShower =orig.fNmyEcalShower;
127  // fNmyTrdTrack =orig.fNmyTrdTrack;
128  // fNmyBeta =orig.fNmyBeta;
129  // fNmyBetaH =orig.fNmyBetaH;
130  // fNmyRichRing =orig.fNmyRichRing;
131 
132  // fNmyTrTrackPlus=orig.fNmyTrTrackPlus;
133  // fNmyEcalShowerPlus =orig.fNmyEcalShowerPlus;
134  // fNmyTrdKFromTrTrack =orig.fNmyTrdKFromTrTrack;
135  // fNmyTrdQtFromTrTrack =orig.fNmyTrdQtFromTrTrack;
136  // fNmyBetaPlus =orig.fNmyBetaPlus;
137  // fNmyBetaHPlus =orig.fNmyBetaHPlus;
138  // fNmyRichRingPlus =orig.fNmyRichRingPlus;
139 
140  if (orig.RTI) RTI= new myRTI(*orig.RTI);
141  else RTI=0;
142 
143  LiveTime=orig. LiveTime;
144  DeltaT=orig. DeltaT;
145  Lvl1Time=orig. Lvl1Time;
147  DeltaTMine=orig. DeltaTMine;
148  TofFlag1=orig. TofFlag1;
149  TofFlag2=orig. TofFlag2;
150  JMembPatt=orig. JMembPatt;
151  PhysBPatt=orig. PhysBPatt;
154  for (int ii=0;ii<4;ii++) TofPatt1[ii]=orig.TofPatt1[ii];
155  for (int ii=0;ii<4;ii++) TofPatt2[ii]=orig.TofPatt2[ii];
156  EcalFlag=orig. EcalFlag;
157  for (int ii=0;ii<19;ii++) TrigRates[ii]=orig.TrigRates[ii];
158  nAnti=orig. nAnti;
159  AntiPatt=orig. AntiPatt;
161  _IsBadRun=orig. _IsBadRun;
162  RunAnalCat=orig. RunAnalCat;
163  Run=orig. Run;
164  Event=orig. Event;
165  fHeader=orig. fHeader;
166  DeltaTJMDC=orig. DeltaTJMDC;
168  TimeJMDCLast=orig. TimeJMDCLast;
169  Duration=orig. Duration;
170  for (int ii=0;ii<4;ii++) nTofClusterL[ii]=orig. nTofClusterL[ii];
171  nTofCluster=orig. nTofCluster;
172  SensorA=orig. SensorA;
173  SensorC=orig. SensorC;
174  SensorK=orig. SensorK;
175  SensorL=orig. SensorL;
176  SensorM=orig. SensorM;
177  Plane1N_M70=orig. Plane1N_M70;
178  Plane1N_M71=orig. Plane1N_M71;
179  Plane1N_M72=orig. Plane1N_M72;
180  Plane1N_M73=orig. Plane1N_M73;
181  Sensor8=orig. Sensor8;
182  for (int ii=0;ii<3;ii++) GeoMagSphericalCoo[ii]=orig.GeoMagSphericalCoo[ii];
183  LatPred=orig. LatPred;
184  LonPred=orig. LonPred;
185  AltPred=orig. AltPred;
186  LatCGM=orig. LatCGM;
187  LonCGM=orig. LonCGM;
188  RadCGM=orig. RadCGM;
191  Field=orig. Field;
192  Lenght=orig. Lenght;
193  Tdr=orig. Tdr;
194  Udr=orig. Udr;
195  Sdr=orig. Sdr;
196  Rdr=orig. Rdr;
197  Edr=orig. Edr;
198  L1dr=orig. L1dr;
199  L3dr=orig. L3dr;
200  L3Error=orig. L3Error;
201  L3VEvent=orig. L3VEvent;
202  L3TimeD=orig. L3TimeD;
203  for (int ii=0;ii<4;ii++) JINJStatus[ii] =orig.JINJStatus[ii];
204  for (int ii=0;ii<24;ii++) JError[ii] =orig.JError[ii];
205 
206  return;
207 }
208 
209 
211 #ifdef PDEBUG
212  printf("In myEvent::~myEvent\n");
213 #endif
214  Clear();
215  PRINTDEBUG;
216  ptr=0;
217  PRINTDEBUG;
218 }
219 
221 #ifdef PDEBUG
222  printf("In myEvent::init\n");
223 #endif
224 
225  Clear();
226 
227  return;
228 }
229 
231 #ifdef PDEBUG
232  printf("In myEvent::gethead\n");
233 #endif
234 
235  PRINTDEBUG;
236 
237  if (!ptr) {
238  ptr = new myEvent();
239  printf("Object myEvent (%p) created as singleton...\n", ptr);
240  }
241 #ifdef PDEBUG
242  else printf("%s existed (%p)!\n", ptr->ClassName(), ptr);//only for debug
243  printf("Event=%d\n", ptr->Event);//only for debug
244 #endif
245  return ptr;
246 }
247 
249 #ifdef PDEBUG
250  printf("In myEvent::printptr\n");
251 #endif
252 
253  PRINTDEBUG;
254 
255  printf("myEvent pointer is %p...\n", ptr);
256 
257  return;
258 }
259 
260 void myEvent::Clear(Option_t*){
261 #ifdef PDEBUG
262  printf("In myEvent::Clear\n");
263 #endif
264  PRINTDEBUG;
265 
266  kMC=false;
267  if (mm) delete mm;
268  mm=0;
269 
270  PRINTDEBUG;
271 
272  fHeader.Clear();
273 
274  PRINTDEBUG;
275 
276  if (ms) delete ms;
277  ms=0;
278 
279  PRINTDEBUG;
280 
281  us1=0;
282 
283  PRINTDEBUG;
284 
285  vmp.clear();
286 
287  vmt.clear();
288  vme.clear();
289  vmu.clear();
290  vmb.clear();
291  vmbh.clear();
292  vmr.clear();
293 
294  vmtp.clear();
295  vmep.clear();
296  vmup.clear();
297  vmuktp.clear();
298  vmukup.clear();
299  vmuqtp.clear();
300  vmbp.clear();
301  vmbhp.clear();
302  vmrp.clear();
303 
304  PRINTDEBUG;
305 
306  // fNmyParticle=0;
307 
308  // fNmyTrTrack=0;
309  // fNmyEcalShower=0;
310  // fNmyTrdTrack=0;
311  // fNmyBeta=0;
312  // fNmyBetaH=0;
313  // fNmyRichRing=0;
314 
315  // fNmyTrTrackPlus=0;
316  // fNmyEcalShowerPlus=0;
317  // fNmyTrdKFromTrTrack=0;
318  // fNmyTrdQtFromTrTrack=0;
319  // fNmyBetaPlus=0;
320  // fNmyBetaHPlus=0;
321  // fNmyRichRingPlus=0;
322 
323  PRINTDEBUG;
324 
325  _nParticle = -999999;
326 
327  _nTrdTrack = -999999;
328  _nTrdCluster = -999999;
329  _nTrdRawHit = -999999;
330  _nTrdSegment =-999999;
331 
332  PRINTDEBUG;
333 
334  _nEcalShower = -999999;
335 
336  PRINTDEBUG;
337 
338  _nBeta = -999999;
339  _nBetaH = -999999;
340 
341  PRINTDEBUG;
342 
343  _nRichRing = -999999;
344  _nRichHit = -999999;
345 
346  _nTrTrack=-999999;
347  _nTrCluster=-999999;
348  _nTrRecHit=-999999;
349  _nTrRawCluster = -999999;
350 
351  _UTCTime=0;
352 
353  fill_n(_nTrRawClusterL, 9, 0);
354 
355  PRINTDEBUG;
356 
357  LiveTime = -999999;
358  DeltaT = 0xFFFF; // in musec
359  Lvl1Time=-999999;
360  // Lvl1TimePrevious=-999999;//non resettarlo!
361  DeltaTMine = -999999; // in musec
362  TofFlag1 = -999999;
363  TofFlag2 = -999999;
364  JMembPatt = -999999;
365  PhysBPatt = -999999;
366  PhysBPattRestored = -999999;
367  PhysBPattPhys = -999999;
368  fill_n(TofPatt1, 4, 0);
369  fill_n(TofPatt2, 4, 0);
370  EcalFlag= -999999;
371  fill_n(TrigRates, 19,0);
372 
373  PRINTDEBUG;
374 
375  nAnti = -999999;
376  AntiPatt = 0;
377 
378  PRINTDEBUG;
379 
380  ReasonToBeBadRun = "";
381  _IsBadRun = -999999;
382  RunAnalCat = -999999;
383 
384  Run = 0;
385  Event = 99999999;
386 
387  // TimeJMDCFirst=0;//non resettarlo!
388  // TimeJMDCLast=0;//non resettarlo!
389  // Duration=-999999;//non resettarlo!
390 
391  PRINTDEBUG;
392 
393  fill_n(nTofClusterL, 4, 0);
394  nTofCluster=-999999;
395 
396  PRINTDEBUG;
397 
398  SensorA=-999999;
399  SensorC=-999999;
400  SensorK=-999999;
401  SensorL=-999999;
402  SensorM=-999999;
403  Plane1N_M70=-999999;
404  Plane1N_M71=-999999;
405  Plane1N_M72=-999999;
406  Plane1N_M73=-999999;
407  Sensor8=-999999;
408 
409  PRINTDEBUG;
410 
411  fill_n(GeoMagSphericalCoo, 3, 0);
412 
413  LatPred=-999999;
414  LonPred=-999999;
415  AltPred=-999999;
416 
417  Field=-999999;
418 
419  LatCGM=-999999;
420  LonCGM=-999999;
421  RadCGM=-999999;
422 
423  // not cleared since evaluated only once per second
424  // MaxGeoCutoff_p=-999999;
425  // MaxGeoCutOff_n=-999999;
426 
427  PRINTDEBUG;
428 
429  if(RTI) delete RTI;
430  RTI=0;
431 
432  PRINTDEBUG;
433 
434  Lenght=999999;
435  Tdr=999999;
436  Udr=999999;
437  Sdr=999999;
438  Rdr=999999;
439  Edr=999999;
440  L1dr=999999;
441  L3dr=999999;
442  L3Error=999999;
443  L3VEvent=999999;
444  L3TimeD=999999;
445  fill_n(JINJStatus, 4, 0);
446  fill_n(JError, 24, 0);
447 
448  PRINTDEBUG;
449 
450 }
451 
453 
454  int beta_index=-1;
455  int n_betah=0;
456  if ( nBetaH() == 0) return false; // Skip this event
457  n_betah= nBetaH();
458 
459  Int_t btchk = 0;
460  Double_t betat = 0;
461  Int_t max_UseHit=0;
462  Int_t maxPattern=0;
463  myBetaH *bth=0;
464 
465  for (Int_t i = 0; i < n_betah; i++) {
466  myBetaH *bb= pmyBetaH(i);
467  if (!bb) continue;
468  Double_t bt = bb->GetBeta();
469  cout<<" i "<<i
470  <<" bt "<<bt
471  <<" GetUseHit "<<bb->GetUseHit()
472  <<" GetBetaPattern "<<bb->GetBetaPattern()
473  <<endl;
474 
475  if (bt < betat) continue;
476 
477  Int_t chk = 0;
478  if (bb->iTrdTrack()>=0 ) chk++;
479  if (bb->iEcalShower()>=0) chk++;
480 
481  if (bb->GetUseHit() > max_UseHit) chk++;
482  if (bb->GetBetaPattern() == 4444) chk++;
483 
484  if(bb->GetUseHit()>= max_UseHit){
485  max_UseHit=bb->GetUseHit();
486  chk++;
487  }
488  int pattern=(bb->GetBetaPattern()%10)
489  +((bb->GetBetaPattern()/10)%10)
490  +((bb->GetBetaPattern()/100)%10)
491  +((bb->GetBetaPattern()/1000)%10);
492 
493  if(pattern>= maxPattern){
494  maxPattern=pattern;
495  chk++;
496  }
497  if (chk < btchk) continue; // Get the highest quality BetaH
498 
499  bth = bb;
500  betat = bt;
501  btchk = chk;
502  beta_index=i;
503  cout<<" i "<<i
504  <<" bt "<<bt
505  <<" btchk "<<btchk
506  <<" beta_index "<<beta_index
507  <<endl;
508  }
509  if (!bth) return -1; // Skip this event
510 
511  return beta_index;
512 }
513 
514 //---------------------------------------------
515 
517 
518  if (index>=0 && vmp.size()>0) {
519  for (int ii=0; ii<(int)(vmp.size()); ii++) {
520  if (vmp[ii] && ((myObject*)vmp[ii])->iMySelf()==index) {
521  return vmp[ii];
522  }
523  }
524  }
525 
526  return NULL;
527 }
528 
530 
531  if (index>=0 && (int)(vmp.size())>index)
532  return vmp[index];
533 
534  return NULL;
535 }
536 
537 //---------------------------------------------
538 
540 
541  if (index>=0 && vmu.size()>0) {
542  for (int ii=0; ii<(int)(vmu.size()); ii++) {
543  if (vmu[ii] && ((myObject*)vmu[ii])->iMySelf()==index) {
544  return vmu[ii];
545  }
546  }
547  }
548 
549  return NULL;
550 }
551 
553 
554  if (index>=0 && (int)(vmu.size())>index)
555  return vmu[index];
556 
557  return NULL;
558 }
559 
561 
562  if (index>=0 && vmup.size()>0) {
563  for (int ii=0; ii<(int)(vmup.size()); ii++) {
564  if (vmup[ii] && ((myObject*)vmup[ii])->iMySelf()==index) {
565  return vmup[ii];
566  }
567  }
568  }
569 
570  return NULL;
571 }
572 
574 
575  if (index>=0 && (int)(vmup.size())>index)
576  return vmup[index];
577 
578  return NULL;
579 }
580 
581 
583 
584  if (index>=0 && vmt.size()>0) {
585  for (int ii=0; ii<(int)(vmt.size()); ii++) {
586  if (vmt[ii] && ((myObject*)vmt[ii])->iMySelf()==index) {
587  return vmt[ii];
588  }
589  }
590  }
591 
592  return NULL;
593 }
594 
596 
597  if (index>=0 && (int)(vmt.size())>index)
598  return vmt[index];
599 
600  return NULL;
601 }
602 
604 
605  if (index>=0 && vme.size()>0) {
606  for (int ii=0; ii<(int)(vme.size()); ii++) {
607  if (vme[ii] && ((myObject*)vme[ii])->iMySelf()==index) {
608  return vme[ii];
609  }
610  }
611  }
612 
613  return NULL;
614 }
615 
617 
618  if (index>=0 && (int)(vme.size())>index)
619  return vme[index];
620 
621  return NULL;
622 }
623 
625 
626  if (index>=0 && vmb.size()>0) {
627  for (int ii=0; ii<(int)(vmb.size()); ii++) {
628  if (vmb[ii] && ((myObject*)vmb[ii])->iMySelf()==index) {
629  return vmb[ii];
630  }
631  }
632  }
633 
634  return NULL;
635 }
636 
638 
639  if (index>=0 && (int)(vmb.size())>index)
640  return vmb[index];
641 
642  return NULL;
643 }
644 
646 
647  if (index>=0 && vmbh.size()>0) {
648  for (int ii=0; ii<(int)(vmbh.size()); ii++) {
649  if (vmbh[ii] && ((myObject*)vmbh[ii])->iMySelf()==index) {
650  return vmbh[ii];
651  }
652  }
653  }
654 
655  return NULL;
656 }
657 
659 
660  if (index>=0 && (int)(vmbh.size())>index)
661  return vmbh[index];
662 
663  return NULL;
664 }
665 
667 
668  if (index>=0 && vmr.size()>0) {
669  for (int ii=0; ii<(int)(vmr.size()); ii++) {
670  if (vmr[ii] && ((myObject*)vmr[ii])->iMySelf()==index) {
671  return vmr[ii];
672  }
673  }
674  }
675 
676  return NULL;
677 }
678 
680 
681  if (index>=0 && (int)(vmr.size())>index)
682  return vmr[index];
683 
684  return NULL;
685 }
686 
687 //--------------------
688 
690 
691  if (index>=0 && vmuktp.size()>0) {
692  for (int ii=0; ii<(int)(vmuktp.size()); ii++) {
693  if (vmuktp[ii] && ((myObject*)vmuktp[ii])->iMySelf()==index) {
694  return vmuktp[ii];
695  }
696  }
697  }
698 
699  return NULL;
700 }
702  if (index>=0 && vmukup.size()>0) {
703  for (size_t ii=0; ii<vmukup.size(); ii++) {
704  myTrdK * k = vmukup[ii];
705  if (k && k->iMySelf()==index) { return k; }
706  }
707  }
708  return NULL;
709 }
710 
712 
713  if (index>=0 && (int)(vmuktp.size())>index)
714  return vmuktp[index];
715 
716  return NULL;
717 }
718 
720 
721  if (index>=0 && (int)(vmukup.size())>index)
722  return vmukup[index];
723 
724  return NULL;
725 }
726 
728 
729  if (index>=0 && vmuqtp.size()>0) {
730  for (int ii=0; ii<(int)(vmuqtp.size()); ii++) {
731  if (vmuqtp[ii] && ((myObject*)vmuqtp[ii])->iMySelf()==index) {
732  return vmuqtp[ii];
733  }
734  }
735  }
736 
737  return NULL;
738 }
739 
741 
742  if (index>=0 && (int)(vmuqtp.size())>index)
743  return vmuqtp[index];
744 
745  return NULL;
746 }
747 
749 
750  if (index>=0 && vmtp.size()>0) {
751  for (int ii=0; ii<(int)(vmtp.size()); ii++) {
752  if (vmtp[ii] && ((myObject*)vmtp[ii])->iMySelf()==index) {
753  return vmtp[ii];
754  }
755  }
756  }
757 
758  return NULL;
759 }
760 
762 
763  if (index>=0 && (int)(vmtp.size())>index)
764  return vmtp[index];
765 
766  return NULL;
767 }
768 
770 
771  if (index>=0 && vmep.size()>0) {
772  for (int ii=0; ii<(int)(vmep.size()); ii++) {
773  if (vmep[ii] && ((myObject*)vmep[ii])->iMySelf()==index) {
774  return vmep[ii];
775  }
776  }
777  }
778 
779  return NULL;
780 }
781 
783 
784  if (index>=0 && (int)(vmep.size())>index)
785  return vmep[index];
786 
787  return NULL;
788 }
789 
791 
792  if (index>=0 && vmbp.size()>0) {
793  for (int ii=0; ii<(int)(vmbp.size()); ii++) {
794  if (vmbp[ii] && ((myObject*)vmbp[ii])->iMySelf()==index) {
795  return vmbp[ii];
796  }
797  }
798  }
799 
800  return NULL;
801 }
802 
804 
805  if (index>=0 && (int)(vmbp.size())>index)
806  return vmbp[index];
807 
808  return NULL;
809 }
810 
812 
813  if (index>=0 && vmbhp.size()>0) {
814  for (int ii=0; ii<(int)(vmbhp.size()); ii++) {
815  if (vmbhp[ii] && ((myObject*)vmbhp[ii])->iMySelf()==index) {
816  return vmbhp[ii];
817  }
818  }
819  }
820 
821  return NULL;
822 }
823 
825 
826  if (index>=0 && (int)(vmbhp.size())>index)
827  return vmbhp[index];
828 
829  return NULL;
830 }
831 
833 
834  if (index>=0 && vmrp.size()>0) {
835  for (int ii=0; ii<(int)(vmrp.size()); ii++) {
836  if (vmrp[ii] && ((myObject*)vmrp[ii])->iMySelf()==index) {
837  return vmrp[ii];
838  }
839  }
840  }
841 
842  return NULL;
843 }
844 
846 
847  if (index>=0 && (int)(vmrp.size())>index)
848  return vmrp[index];
849 
850  return NULL;
851 }
852 
853 bool pnpoly(int npol, float *xp, float *yp, float x, float y){
854 
855  int i, j;
856  bool c = false;
857 
858  for (i = 0, j = npol-1; i < npol; j = i++) {
859  if (
860  (((yp[i] <= y) && (y < yp[j])) ||
861  ((yp[j] <= y) && (y < yp[i]))) &&
862  (x < (xp[j] - xp[i]) * (y - yp[i])/(yp[j] - yp[i]) + xp[i]))
863  c = !c;
864  }
865 
866  return c;
867 }
868 
869 Bool_t myEvent::InSAA() {
870 
871  static float Phi_SAA[5] = {-83.0, -38.0, 0.0, 0.0, -83.0};
872  static float Theta_SAA[5] = {-1.0, -1.0, -22.0, -60.0, -60.0};
873 
874  return pnpoly(5, Phi_SAA, Theta_SAA, Lon(), Lat());
875 }
876 
877 Int_t myEvent::isInShadow(myPoint &pt, int ipart){
878 
879  myParticle* mp = pmyParticle(ipart);
880 
881  if (mp) {
882  return mp->isInShadow(pt);
883  }
884 
885  return -1;//no particle
886 }
887 
888 #ifdef _WITHGBATCH_
889 int myEvent::GetRTI(AMSSetupR::RTI & a){
890 
891  return AMSEventR::getsetup()->getRTI(a,this->fHeader.Time[0]);
892 }
893 
894 #endif
895 
896 int myEvent::LoadRTI(unsigned int t1, unsigned int t2, const char *dir){
897 
898  if(!myChain::gethead()->HasSectionActivated("RTI") ){
899  cerr<< " Section RTI not available or not activated "<<endl;
900  return 2;
901  }
902  TTree* t3rti = myChain::gethead()->GetSection("RTI")->t3friend->GetTree();
903  if (!t3rti){
904  cerr<< " RTI TTree friend not available "<<endl;
905  return 2;
906  }
907  if(t1>t2){
908  cerr<< "LoadmyRTI-S-BegintimeNotLessThanEndTime "<<t1<<" "<<t2<<endl;
909  return 2;
910  }
911  else if(t2-t1>864000){
912  cerr<< "LoadmyRTI-S-EndBeginDifferenceTooBigMax864000 "<<t2-t1<<endl;
913  if(t1<1305000000){
914  t1=t2-864000;
915  }
916  else{
917  t2=t1+864000;
918  }
919  }
920 
921  myRTI *a;
922  t3rti->SetBranchAddress("fmyRTI",a);
923  int bfound=0;
924  int efound=0;
925  for(int i_rti=0; i_rti<t3rti->GetEntries(); i_rti++){
926  t3rti->GetEntry(i_rti);
927  if(!a) continue;
928  if(a->run==0) continue; //missing second
929  unsigned int nt=a->utime;
930  if(nt<t1){bfound=1;continue;}//beg found
931  if(nt>=t1&&nt<=t2){
932  if(bfound!=2){
933  fRTI.clear();bfound=2;
934  }
935  fRTI.insert(make_pair(nt,*a));
936  }//found
937  else if(nt>t2){efound=1; break;}//end
938  }
939  int ret;
940  if(bfound&&efound)ret=0;//All found
941  else if(!bfound&&!efound)ret=2;//All not found
942  else ret=1;//Only One Found
943  cout<< "LoadmyRTI-I- "<<fRTI.size()<<" Entries Loaded "<<ret<<endl;
944 
945  return ret;
946 }
947 
948 
950 
951 
952  a = *(this->RTI);
953  if(this->RTI) return 0;
954  else return 1;
955 }
956 
957 
958 int myEvent::GetRTI(myRTI & a, unsigned int xtime){
959 
960  static unsigned int stime[2]={1,1};
961  static int vrti=-1;
962 
963  const int pt=3600*3;
964  const int dt=3600*24;
965  if(stime[0]==1||xtime>stime[1]||xtime<stime[0]){
966  stime[0]=(xtime<=pt)?1:xtime-pt;
967  stime[1]=xtime+dt;
968  fRTI.clear();
969  this->LoadRTI(stime[0],stime[1]);
970  }
971  //---Status
972  myRTI b;
973  a=b;
974  map< unsigned int, myRTI >::iterator k=fRTI.lower_bound(xtime);
975  if (fRTI.size()==0)return 2;
976  if(k==fRTI.end())return 1;
977 
978  if(xtime==k->first){//find
979  a=(k->second);
980  return 0;
981  }
982  return 2;
983 }
984 
985 int myEvent::GetRTIdL1L9(int extlay,myPoint &nxyz, myPoint &dxyz,unsigned int xtime,unsigned int dt, int rti_flag){
986  unsigned int bt= xtime/dt*dt;
987  unsigned int et= bt+dt-1;
988 
989  static unsigned int rbt=0;
990  static unsigned int ret=0;
991  static unsigned int rst=0;//Eff dt
992  static myPoint rnxyz[2];
993  static myPoint rdxyz[2];
994 
995  //----New External Layer If
996  if(!(bt>=rbt&&et<=ret)){ //First Time arrive
997  rst=0;
998  for(int iexl=0;iexl<2;iexl++){rnxyz[iexl].setp(0,0,0);rdxyz[iexl].setp(0,0,0);}
999  //----Sum BT
1000 #ifdef _WITHGBATCH_
1001  AMSSetupR::RTI a;
1002 #endif
1003  myRTI mya;
1004  for(unsigned int t=bt;t<=et;t++){
1005 #ifdef _WITHGBATCH_
1006  if(rti_flag==0){
1007  if(GetRTI(mya,t)!=0) continue;
1008  }else{
1009  if(AMSEventR::GetRTI(a,t)!=0)continue;
1010  }
1011 #else
1012  if(GetRTI(mya,t)!=0) continue;
1013 #endif
1014  for(int iexl=0;iexl<2;iexl++){
1015  for(int ico=0;ico<3;ico++){
1016  double nev=0;
1017 #ifdef _WITHGBATCH_
1018  if(rti_flag==0){
1019  nev=a.nl1l9[iexl][ico==0?0:1];
1020  rdxyz[iexl][ico]+=a.dl1l9[iexl][ico]*nev;
1021  }
1022  else{
1023  nev=mya.nl1l9[iexl][ico==0?0:1];
1024  rdxyz[iexl][ico]+=mya.dl1l9[iexl][ico]*nev;
1025  }
1026 #else
1027  nev=mya.nl1l9[iexl][ico==0?0:1];
1028  rdxyz[iexl][ico]+=mya.dl1l9[iexl][ico]*nev;
1029 #endif
1030  rnxyz[iexl][ico]+=nev;//X Y Z Events number
1031  }
1032  }
1033  rst++;
1034  }
1035  //---Calculate Mean
1036  for(int iexl=0;iexl<2;iexl++){
1037  for(int ico=0;ico<3;ico++){
1038  rdxyz[iexl][ico]=(rnxyz[iexl][ico]>0)?rdxyz[iexl][ico]/rnxyz[iexl][ico]:0;
1039  }
1040  }
1041  }
1042 
1043  nxyz=rnxyz[extlay]; dxyz=rdxyz[extlay];
1044  rbt=bt; ret=et;
1045  return rst;
1046 }
1047 
1048 
1049 //---------------------------------------------
1050 
1051 //-------------------------------------------------------------------------
1052 
1053 #ifdef _WITHGBATCH_
1054 
1055 //--------------------------------------------------------------------
1056 
1057 ClassImp(myEventFiller);
1058 
1059 //--------------------------------------------------------------------
1060 
1061 static int TRDWeakForEPSeparation(AMSEventR* pev);
1062 static int TrdRunCategory(AMSEventR* pev);
1063 static bool BadRunCheck(AMSEventR *pev);
1064 static int IsScienceRun(AMSEventR *pev);
1065 static int RunAnalysisCategory(AMSEventR *pev);
1066 
1067 /*
1068 bool myEventFiller:: NoTRDPlus=false;
1069 bool myEventFiller:: NoTRDKPlus=false;
1070 bool myEventFiller:: NoTRDQtPlus=false;
1071 bool myEventFiller:: NoEcalPlus=false;
1072 bool myEventFiller:: NoBetaPlus=false;
1073 bool myEventFiller:: NoBetaHPlus=false;
1074 bool myEventFiller:: NoRichPlus=false;
1075 bool myEventFiller:: NoTrackerPlus=false;
1076 bool myEventFiller:: NoHeaderTree=false;
1077 */
1078 
1079 myEventFiller::myEventFiller():myEvent(){
1080 #ifdef PDEBUG
1081  printf("In myEventFiller::myEventFiller\n");
1082 #endif
1083  PRINTDEBUG;
1084  init();
1085  PRINTDEBUG;
1086  ptr=this;
1087 }
1088 
1089 myEventFiller::~myEventFiller(){
1090 #ifdef PDEBUG
1091  printf("In myEventFiller::~myEventFiller\n");
1092 #endif
1093  PRINTDEBUG;
1094  Clear();
1095  PRINTDEBUG;
1096  ptr = 0;
1097  PRINTDEBUG;
1098 }
1099 
1100 myEventFiller* myEventFiller::gethead() {
1101 #ifdef PDEBUG
1102  printf("In myEventFiller::gethead\n");
1103 #endif
1104 
1105  PRINTDEBUG;
1106 
1107  if (!ptr) {
1108  ptr = new myEventFiller();
1109  printf("Object myEventFiller (%p) created as singleton...\n", ptr);
1110  }
1111  else printf("myEventFiller (%s) exists!\n", ptr->ClassName());//only for debug
1112  return (myEventFiller*)ptr;
1113 }
1114 
1115 void myEventFiller::init() {
1116 #ifdef PDEBUG
1117  printf("In myEventFiller::init\n");
1118 #endif
1119 
1120  myEvent::init();
1121 
1122  for (int ii=0; ii<9; ii++) {
1123  if(TkDBc::Head) zlay[ii]=TkDBc::Head->GetZlayer(ii+1);
1124  // printf("%f\n", zlay[ii]);
1125  }
1126 
1127  Clear();
1128 
1129  return;
1130 }
1131 
1132 void myEventFiller::Clear(Option_t*){
1133 #ifdef PDEBUG
1134  printf("In myEventFiller::Clear\n");
1135 #endif
1136  PRINTDEBUG;
1137 
1138  myEvent::Clear();
1139 
1140  PRINTDEBUG;
1141 
1142  tmp_filler.SetOwner(kTRUE);
1143  tmp_filler.Clear();//since 'owner' this destroy all the myObject's hold by it
1144 
1145  PRINTDEBUG;
1146 
1147  mcevent = 0;
1148 
1149  pev = 0;
1150 
1151  head = 0;
1152 
1153  lvl1 = 0;
1154 
1155  tkrechitsevent = 0;
1156 
1157  setup = 0;
1158 
1159  slowcontrol = 0;
1160 
1161  daqev = 0;
1162 
1163 #if !defined _B524_ && !defined _B550_ && !defined _B572_
1164  pdsperr = 0;
1165 #endif
1166 
1167  PRINTDEBUG;
1168 }
1169 
1170 void myEventFiller::Fill(int fTree, Long64_t fEntry){
1171 #ifdef PDEBUG
1172  printf("In myEventFiller::Fill\n");
1173 #endif
1174 
1175  PRINTDEBUG;
1176 
1177  Clear();
1178 
1179  PRINTDEBUG;
1180  /* TODO not optimized, string finding every event... */
1181 
1182  myHeaderFiller mhfill;
1183  mhfill.Fill();
1184  fHeader = (myHeader) mhfill;
1185 
1186  PRINTDEBUG;
1187 
1188  Fill();
1189 
1190  PRINTDEBUG;
1191 
1192  mcevent = pev->pMCEventg(0);
1193  if (mcevent) {
1194  myMCFiller mmfill;
1195  mmfill.Fill(mcevent);
1196  mm = new myMC();
1197  *mm = mmfill;
1198  kMC = true;
1199  // printf("MC block...\n");//only for debug
1200  }
1201  else kMC = false;
1202 
1203  PRINTDEBUG;
1204 
1205 #ifdef PDEBUG
1206  printf("Loop over TrdTrack's (%d)\n", _nTrdTrack);//only for debug
1207 #endif
1208  for (int ii=0; ii<_nTrdTrack; ii++) {
1209  TrdTrackR* trdtrack = pev->pTrdTrack(ii);
1210  PRINTDEBUG;
1211  if (trdtrack) {
1212  myTrdTrackFiller mu;
1213  mu.SetMySelf(ii);
1214  PRINTDEBUG;
1215  mu.Fill(trdtrack);
1216  PRINTDEBUG;
1217  myTrdTrack* mu2bewritten = new myTrdTrack(mu);
1218  tmp_filler.Add(mu2bewritten);
1219  vmu.push_back(mu2bewritten);
1220  vmukup.push_back(nullptr); // it's indicized with trd track
1221  // so far it has NO plus
1222  }
1223  PRINTDEBUG;
1224  }
1225 
1226  PRINTDEBUG;
1227  if (gsection.enabled("TRDPlus")) {
1228  if(pev->nTrdSegment()>0){
1229  myTrdTrackPlusFiller mup;
1230  mup.SetMySelf(0);
1231  PRINTDEBUG;
1232  mup.Fill(pev);
1233  PRINTDEBUG;
1234  myTrdTrackPlus* mup2bewritten = new myTrdTrackPlus(mup);
1235  tmp_filler.Add(mup2bewritten);
1236  vmup.push_back(mup2bewritten);
1237  PRINTDEBUG;
1238  }
1239  }
1240 
1241  PRINTDEBUG;
1242 
1243 #ifdef PDEBUG
1244  printf("Loop over TrTrack's (%d)\n", _nTrTrack);
1245 #endif
1246  for (int ii=0; ii<_nTrTrack; ii++) {
1247  TrTrackR* track = pev->pTrTrack(ii);
1248  PRINTDEBUG;
1249  if (track) {
1250  myTrTrackFiller mt;
1251  mt.SetMySelf(ii);
1252  PRINTDEBUG;
1253  mt.Fill(track);
1254  PRINTDEBUG;
1255  myTrTrack* mt2bewritten = new myTrTrack(mt);
1256  tmp_filler.Add(mt2bewritten);
1257  vmt.push_back(mt2bewritten);
1258  vmtp.push_back(NULL);
1259  vmuktp.push_back(NULL);//also the myTrdKFromTrTrack is 'indicized' as the myTrTrack
1260  vmuqtp.push_back(NULL);//also the myTrdQtFromTrTrack is 'indicized' as the myTrTrack
1261 #ifdef PDEBUG
1262  printf("track=%d) iPart=%d, iMySelf=%d, i_part=%d, i_myself=%d\n", ii, mt.iPart(), mt.iMySelf(), mt.i_part, mt.i_myself);
1263 #endif
1264  }
1265  PRINTDEBUG;
1266  }
1267 
1268  PRINTDEBUG;
1269 
1270 #ifdef PDEBUG
1271  printf("Loop over EcalShower's (%d)\n", _nEcalShower);
1272 #endif
1273  for (int ii=0; ii<_nEcalShower; ii++) {
1274  EcalShowerR* shower = pev->pEcalShower(ii);
1275  PRINTDEBUG;
1276  if (shower) {
1277  myEcalShowerFiller me;
1278  me.SetMySelf(ii);
1279  PRINTDEBUG;
1280  me.Fill(shower);
1281  PRINTDEBUG;
1282  myEcalShower* me2bewritten = new myEcalShower(me);
1283  tmp_filler.Add(me2bewritten);
1284  vme.push_back(me2bewritten);
1285  vmep.push_back(NULL);
1286  }
1287  PRINTDEBUG;
1288  }
1289 
1290  PRINTDEBUG;
1291 
1292 #ifdef PDEBUG
1293  printf("Loop over RichRing's (%d)\n", _nRichRing);//only for debug
1294 #endif
1295  RichRingR::setBetaCorrection(RichRingR::fullUniformityCorrection);
1296  for (int ii=0; ii<_nRichRing; ii++) {
1297  RichRingR* ring = pev->pRichRing(ii);
1298  PRINTDEBUG;
1299  if (ring) {
1300  myRichRingFiller mr;
1301  mr.SetMySelf(ii);
1302  PRINTDEBUG;
1303  mr.Fill(ring);
1304  PRINTDEBUG;
1305  myRichRing* mr2bewritten = new myRichRing(mr);
1306  tmp_filler.Add(mr2bewritten);
1307  vmr.push_back(mr2bewritten);
1308  vmrp.push_back(NULL);
1309  }
1310  PRINTDEBUG;
1311  }
1312 
1313  PRINTDEBUG;
1314 
1315 #ifdef PDEBUG
1316  printf("Loop over Beta's (%d)\n", _nBeta);
1317 #endif
1318  for (int ii=0; ii<_nBeta; ii++) {
1319  BetaR* beta = pev->pBeta(ii);
1320  PRINTDEBUG;
1321  if (beta) {
1322  myBetaFiller mb;
1323  mb.SetMySelf(ii);
1324  PRINTDEBUG;
1325  mb.Fill(beta);
1326  PRINTDEBUG;
1327  myBeta* mb2bewritten = new myBeta(mb);
1328  tmp_filler.Add(mb2bewritten);
1329  vmb.push_back(mb2bewritten);//questo crasha
1330  vmbp.push_back(NULL);
1331  }
1332  PRINTDEBUG;
1333  }
1334 
1335  PRINTDEBUG;
1336 
1337 #ifdef PDEBUG
1338  printf("Loop over BetaH's (%d)\n", _nBetaH);
1339 #endif
1340  for (int ii=0; ii<_nBetaH; ii++) {
1341  BetaHR* betah = pev->pBetaH(ii);
1342  PRINTDEBUG;
1343  if (betah) {
1344  myBetaHFiller mbh;
1345  mbh.SetMySelf(ii);
1346  PRINTDEBUG;
1347  mbh.Fill(betah);
1348  PRINTDEBUG;
1349  myBetaH* mbh2bewritten = new myBetaH(mbh);
1350  tmp_filler.Add(mbh2bewritten);
1351  vmbh.push_back(mbh2bewritten);
1352  vmbhp.push_back(NULL);
1353  }
1354  PRINTDEBUG;
1355  }
1356 
1357  PRINTDEBUG;
1358 
1359  int i_part_max_qbh=-1;
1360  float max_qbh=0.;
1361 
1362  int i_part_max_r=-1;
1363  float max_r=0.;
1364  int i_part_max_r_trd=-1;
1365  float max_r_trd=0.;
1366  int i_part_max_e=-1;
1367  float max_e=0.;
1368  // int i_part_complete=-1;
1369 
1370  PRINTDEBUG;
1371 
1372 #ifdef PDEBUG
1373  printf("Loop over Particle's (%d)\n", _nParticle);
1374 #endif
1375 
1376  for (int ii=0; ii<_nParticle; ii++) {
1377  myParticleFiller mp;
1378  mp.Fill(pev->pParticle(ii));
1379  mp.SetPart(ii);
1380  mp.SetMySelf(ii);
1381 
1382  PRINTDEBUG;
1383 
1384  if (mp.trdtrack && mp.pmyTrdTrackByMySelf()) mp.pmyTrdTrackByMySelf()->SetPart(ii);
1385  PRINTDEBUG;
1386  if (mp.track && mp.pmyTrTrackByMySelf()) mp.pmyTrTrackByMySelf()->SetPart(ii);
1387  PRINTDEBUG;
1388  if (mp.shower && mp.pmyEcalShowerByMySelf()) mp.pmyEcalShowerByMySelf()->SetPart(ii);
1389  PRINTDEBUG;
1390  if (mp.ring && mp.pmyRichRingByMySelf()) mp.pmyRichRingByMySelf()->SetPart(ii);
1391  PRINTDEBUG;
1392  if (mp.beta && mp.pmyBetaByMySelf()) mp.pmyBetaByMySelf()->SetPart(ii);
1393  PRINTDEBUG;
1394  if (mp.betah && mp.pmyBetaHByMySelf()) mp.pmyBetaHByMySelf()->SetPart(ii);
1395  PRINTDEBUG;
1396 #ifdef PDEBUG
1397  if (mp.track) printf("part=%d) mp.pmyTrTrack(), iPart=%d, iMySelf=%d, i_part=%d, i_myself=%d\n", ii, mp.pmyTrTrackByMySelf()->iPart(), mp.pmyTrTrackByMySelf()->iMySelf(), mp.pmyTrTrackByMySelf()->i_part, mp.pmyTrTrackByMySelf()->i_myself);
1398  if (mp.track) printf("mpart=%d) vmt[%d], iPart=%d, iMySelf=%d, i_part=%d, i_myself=%d\n", ii, mp.iTrTrack(), vmt[mp.iTrTrack()]->iPart(), vmt[mp.iTrTrack()]->iMySelf(), vmt[mp.iTrTrack()]->i_part, vmt[mp.iTrTrack()]->i_myself);
1399 #endif
1400 
1401  PRINTDEBUG;
1402 
1403  bool NoEcalPlus = not gsection.enabled("EcalPlus"),
1404  NoHeaderTree = not gsection.enabled("HeaderTree");
1405  if (!(NoEcalPlus && NoHeaderTree) ) {
1406  if (mp.shower) {
1407  myEcalShowerPlusFiller* mep = new myEcalShowerPlusFiller();
1408  PRINTDEBUG;
1409  // cases:
1410  // NoEcalPlus | NoHeaderTree --> Fill(EcalShowerR*, short)
1411  // 0 0 --> Fill(EcalShowerR*, 0), Fill is called normally, OK
1412  // 0 1 --> Fill(EcalShowerR*, 1), Fill is called normally, OK
1413  // 1 0 --> Fill(EcalShowerR*, 1), Fill is called "short" , OK
1414  // 1 1 --> Fill(EcalShowerR*, 1), Fill is called normally, KO
1415  // but we didn't arrive here since there's the if on top
1416  mep->Fill(mp.shower, NoEcalPlus&(!NoHeaderTree));
1417  PRINTDEBUG;
1418  mep->SetPart(ii);
1419  mep->SetMySelf(mp.pp->iEcalShower());
1420  myEcalShowerPlus* mep2bewritten = new myEcalShowerPlus(*mep);
1421  tmp_filler.Add(mep2bewritten);
1422  vmep[mep2bewritten->iMySelf()] = mep2bewritten;
1423  if(mp.shower->EnergyD>=max_e){
1424  max_e=mp.shower->EnergyD;
1425  i_part_max_e=ii;
1426  }
1427  if (mep) delete mep;
1428  mep=0;
1429  }
1430  }
1431 
1432  PRINTDEBUG;
1433 
1434  /* have to put here because Trd*plus need track */
1435  bool NoTrackerPlus = not gsection.enabled("TrackerPlus");
1436  if (!NoTrackerPlus) {
1437  if (mp.track) {
1438  myTrTrackPlusFiller* mtp = new myTrTrackPlusFiller();
1439  PRINTDEBUG;
1440  Double_t beta=999;
1441  if (mp.pmyBetaHByMySelf()) beta=mp.pmyBetaHByMySelf()->Beta;
1442  mtp->Fill(mp.track, ii, mp.shower, beta, kMC, true);
1443  PRINTDEBUG;
1444  mtp->FillCharge(mp.track, beta);
1445  PRINTDEBUG;
1446  mtp->SetPart(ii);
1447  mtp->SetMySelf(mp.pp->iTrTrack());
1448  myTrTrackPlus* mtp2bewritten = new myTrTrackPlus(*mtp);
1449  tmp_filler.Add(mtp2bewritten);
1450  vmtp[mtp2bewritten->iMySelf()] = mtp2bewritten;
1451  if(mtp->GetRigidity(0)>=max_r){
1452  max_r=mtp->GetRigidity(0);
1453  i_part_max_r=ii;
1454  }
1455  if (mtp) delete mtp;
1456  mtp=0;
1457  }
1458  }
1459 
1460  PRINTDEBUG;
1461 
1462  if( gsection.enabled("BetaHPlus") ){
1463  if ( mp.betah && mp.pmyBetaHByMySelf()) {
1464  myBetaHPlusFiller* mbhp = new myBetaHPlusFiller();
1465  PRINTDEBUG;
1466  mbhp->Fill(mp.betah);
1467  PRINTDEBUG;
1468  mbhp->SetPart(ii);
1469  mbhp->SetMySelf(mp.pp->iBetaH());
1470  myBetaHPlus* mbhp2bewritten = new myBetaHPlus(*mbhp);
1471  tmp_filler.Add(mbhp2bewritten);
1472  vmbhp[mbhp2bewritten->iMySelf()] = mbhp2bewritten;
1473  if(mbhp->Q>=max_qbh){
1474  max_qbh=mbhp->Q;
1475  i_part_max_qbh=ii;
1476  }
1477  if (mbhp) delete mbhp;
1478  mbhp=0;
1479  }
1480  }
1481 
1482  PRINTDEBUG;
1483 
1484  if( gsection.enabled("BetaPlus")){
1485  if (mp.beta && mp.pmyBetaByMySelf()) {
1486  myBetaPlusFiller* mbp = new myBetaPlusFiller();
1487  PRINTDEBUG;
1488  if (mp.pmyTrTrackByMySelf()) mbp->Fill(mp.beta, mp.track, mp.pmyTrTrackByMySelf()->kDef);
1489  else mbp->Fill(mp.beta, mp.track);
1490  PRINTDEBUG;
1491  mbp->SetPart(ii);
1492  mbp->SetMySelf(mp.pp->iBeta());
1493  myBetaPlus* mbp2bewritten = new myBetaPlus(*mbp);
1494  tmp_filler.Add(mbp2bewritten);
1495  vmbp[mbp2bewritten->iMySelf()] = mbp2bewritten;
1496  if (mbp) delete mbp;
1497  mbp=0;
1498  }
1499  }
1500 
1501  PRINTDEBUG;
1502 
1503  if( gsection.enabled("RichPlus")){
1504  if (mp.ring && mp.pmyRichRingByMySelf()) {
1505  myRichRingPlusFiller* mrp = new myRichRingPlusFiller();
1506  PRINTDEBUG;
1507  mrp->Fill(mp.ring, mp.pp);
1508  PRINTDEBUG;
1509  mrp->SetPart(ii);
1510  mrp->SetMySelf(mp.pp->iRichRing());
1511  myRichRingPlus* mrp2bewritten = new myRichRingPlus(*mrp);
1512  tmp_filler.Add(mrp2bewritten);
1513  vmrp[mrp2bewritten->iMySelf()] = mrp2bewritten;
1514  if (mrp) delete mrp;
1515  mrp=0;
1516  }
1517  }
1518 
1519  PRINTDEBUG;
1520  if (gsection.enabled("TRDKPlus")) {
1521  if (mp.track) {
1522  myTrdKFromTrTrackFiller* mukp = new myTrdKFromTrTrackFiller();
1523  PRINTDEBUG;
1524  float energy=0;
1525  if (mp.pmyEcalShowerByMySelf()) energy=mp.pmyEcalShowerByMySelf()->EnergyE;
1526  int kDef=0;
1527  if (mp.pmyTrTrackPlusByMySelf()) kDef=mp.pmyTrTrackPlusByMySelf()->kDef;
1528  if( kDef==0 ){
1529  if(!NoTrackerPlus)Error(__func__,"strange kDef for %p", mp.pmyTrTrackPlusByMySelf());
1530  kDef = mp.track->Gettrdefaultfit();
1531  }
1532  mukp->Fill(mp.iTrTrack(), mp.track, energy, kDef);
1533  PRINTDEBUG;
1534  mukp->SetPart(ii);
1535  mukp->SetMySelf(mp.pp->iTrTrack());//TrdKFromTrTrack is 'indicized' with the TrTrack used
1536  myTrdK* mukp2bewritten = new myTrdK(*mukp);
1537  tmp_filler.Add(mukp2bewritten);
1538  vmuktp[mukp2bewritten->iMySelf()] = mukp2bewritten;
1539  if(mp.pmyTrTrackByMySelf() && mp.pmyTrTrackByMySelf()->Rigidity>=max_r_trd){
1540  max_r_trd=mp.pmyTrTrackByMySelf()->Rigidity;
1541  i_part_max_r_trd=ii;
1542  }
1543  if (mukp) delete mukp;
1544  mukp=0;
1545  }
1546  if (mp.trdtrack ) {
1547  myTrdKFromTrdTrackFiller mukup;
1548  PRINTDEBUG;
1549  float rig = std::abs(pev->Particle(ii).Momentum / pev->Particle(ii).Charge);
1550  float energy=0;
1551  if (mp.pmyEcalShowerByMySelf()) energy=mp.pmyEcalShowerByMySelf()->EnergyE;
1552  mukup.Fill(mp.iTrdTrack(), mp.trdtrack, energy, rig);
1553  PRINTDEBUG;
1554  mukup.SetPart(ii);
1555  mukup.SetMySelf(mp.pp->iTrdTrack());//TrdKFromTrdTrack is 'indicized' with the TrdTrack used
1556  myTrdK* mukp2bewritten = new myTrdK(mukup);
1557  tmp_filler.Add(mukp2bewritten);
1558  vmukup[mukp2bewritten->iMySelf()] = mukp2bewritten;
1559  }
1560  }
1561 
1562  if (gsection.enabled("TRDQtPlus")) {
1563  if (mp.track) {
1564  myTrdQtFromTrTrackFiller* muqtp = new myTrdQtFromTrTrackFiller();
1565  PRINTDEBUG;
1566  float energy=0;
1567  if (mp.pmyEcalShowerByMySelf()) energy=mp.pmyEcalShowerByMySelf()->EnergyE;
1568  int kDef=0;
1569  if (mp.pmyTrTrackByMySelf()) kDef=mp.pmyTrTrackByMySelf()->kDef;
1570  muqtp->Fill(mp.iTrTrack(), mp.track, kDef, energy);
1571  PRINTDEBUG;
1572  muqtp->SetPart(ii);
1573  muqtp->SetMySelf(mp.pp->iTrTrack());//TrdQtFromTrTrack is 'indicized' with the TrTrack used
1574  myTrdQtFromTrTrack* muqtp2bewritten = new myTrdQtFromTrTrack(*muqtp);
1575  tmp_filler.Add(muqtp2bewritten);
1576  vmuqtp[muqtp2bewritten->iMySelf()] = muqtp2bewritten;
1577  if (muqtp) delete muqtp;
1578  muqtp=0;
1579  }
1580  }
1581 
1582  PRINTDEBUG;
1583 
1584  myParticle* mp2bewritten = new myParticle(mp);
1585  tmp_filler.Add(mp2bewritten);
1586  vmp.push_back(mp2bewritten);
1587  PRINTDEBUG;
1588  }
1589 
1590  PRINTDEBUG;
1591  if( gsection.enabled("StatusTree")){
1592 #ifdef PDEBUG
1593  printf("Filling Status \n");//only for debug
1594 #endif
1595  PRINTDEBUG;
1596  myStatusFiller msfill;
1597  msfill.fStatus=pev->fStatus;
1598  msfill.EntryNumber=fEntry;
1599  msfill.TreeNumber=fTree;
1600  msfill.Fill(i_part_max_r, i_part_max_qbh , i_part_max_e, i_part_max_r_trd);
1601  PRINTDEBUG;
1602  //FIXME: why not copy constructor?!
1603  ms = new myStatus();
1604  *ms = msfill;
1605  }
1606  PRINTDEBUG;
1607 
1608  return;
1609 }
1610 
1611 void myEventFiller::Fill(){
1612 #ifdef PDEBUG
1613  printf("In myEventFiller::Fill\n");
1614 #endif
1615  PRINTDEBUG;
1616 
1617  pev = AMSEventR::Head();
1618 
1619  string reason;
1620  if (AMSEventR::getsetup())
1621  AMSEventR::getsetup()->IsBadRun(reason, pev->UTime(), pev->Run());
1622  ReasonToBeBadRun = reason;
1623  _IsBadRun = pev->IsBadRun("");
1624  RunAnalCat = RunAnalysisCategory(pev);
1625 
1626  Run = pev->Run();
1627  Event = pev->Event();
1628 
1629  head = &(pev->fHeader);
1630 
1631 
1632  _UTCTime = pev->UTCTime() ;
1633 
1634  PRINTDEBUG;
1635 
1636  if (!kMC) {
1637  static unsigned int TimeJMDCPrevious = fHeader.Time[0];//in this way also the first round the deltat is correct (0)
1638  static unsigned int MuTimeJMDCPrevious = fHeader.Time[1];//in this way also the first round the deltat is correct (0)
1639  DeltaTJMDC = fHeader.Time[0]+0.000001*fHeader.Time[1] - (TimeJMDCPrevious+0.000001*MuTimeJMDCPrevious);
1640  TimeJMDCPrevious = fHeader.Time[0];
1641  MuTimeJMDCPrevious = fHeader.Time[1];
1642 
1643  if (fHeader.Time[0]<TimeJMDCFirst) TimeJMDCFirst = fHeader.Time[0];
1644  if (fHeader.Time[0]>TimeJMDCLast) TimeJMDCLast = fHeader.Time[0];
1645  Duration = TimeJMDCLast - TimeJMDCFirst;//the total time in the "box"
1646  }
1647 
1648  PRINTDEBUG;
1649 
1650  lvl1 = pev->pLevel1(0);
1651 
1652  setup = pev->getsetup();
1653 
1654  daqev=pev->pDaqEvent(0);
1655 
1656  //-------------------------------------------------------------------------------------
1657  if (!kMC) {
1658  // printf("(Lat, Lon, Alt) = (%f, %f, %f)\n", Lat(), Lon(), Alt()); //only for debug
1659 
1660  GM_GeoMagSphericalCoo(fHeader.Time[0], fHeader.RadS, fHeader.ThetaS, fHeader.PhiS, GeoMagSphericalCoo);
1661 
1662  // printf("(LatMAG, LonMAG, RadMAG) = (%f, %f, %f)\n", LatMAG(), LonMAG(), RadMAG()); //only for debug
1663 
1664 #ifdef PREDICT
1665  static ISSCoo iss;
1666 #endif
1667 #ifdef CGM
1668  static cgmcoo cgm;
1669 #endif
1670 #ifdef FIELD
1671  static GeoMag geomag;
1672 #endif
1673 
1674  if (InSAA()) {
1675  static int counter=0;
1676  if (counter<100) {
1677  counter++;
1678  printf("%d-%d) in SAA (Lon,Lat)=(%f,%f)\n", Run, Event, Lon(), Lat());
1679  }
1680  else if (counter==100) {
1681  counter++;
1682  printf("%d-%d) in SAA (Lon,Lat)=(%f,%f). I said %d times, it's enough...\n", Run, Event, Lon(), Lat(), counter);
1683  }
1684  }
1685 
1686  if ( isISS() and fHeader.Time[0] != TimePrevISS) {//once per second it's enough...
1687  TimePrevISS = fHeader.Time[0];
1688 
1689 #ifdef PREDICT
1690  iss.TrackISS((int)(fHeader.Time[0]), 0);
1691  // iss.Print();
1692 #endif
1693 #ifdef CGM
1694  cgm.GetCGM(Lat, Lon, Alt, (int)(1970+(fHeader.Time[0]/(365*24*60*60))));
1695  // cgm.GetCGM(iss.Lat, iss.Lon, iss.Alt);
1696  // cgm.Print();
1697 #endif
1698 #ifdef FIELD
1699  geomag.Recalc(Lat, Lon, Alt, (int)(1970+(fHeader.Time[0]/(365*24*60*60))));
1700  // geomag.Recalc(iss.Lat, iss.Lon, iss.Alt, 1970+(fHeader.Time[0]/(365*24*60*60)));
1701 #endif
1702 
1703  Double_t cutoff[2];
1704  pev->GetMaxGeoCutoff(35.0, 1, cutoff);
1705  MaxGeoCutOff_n=cutoff[0];
1706  MaxGeoCutOff_p=cutoff[1];
1707 
1708  if(gsection.enabled("RTI")){
1709  AMSSetupR::RTI::Version=2;
1710  AMSSetupR::RTI ev_RTI;
1711  int RTI_ko=pev->GetRTI(ev_RTI);
1712  if (!RTI_ko) {
1713  myRTIFiller rtifill;
1714  rtifill.Fill(&ev_RTI);
1715  if (RTI) delete RTI;
1716  RTI = new myRTI();
1717  *RTI = rtifill;
1718  // printf("%d -- %d\n", Event, RTI->evno);//only for debug
1719  }else Error(__func__, "fail getting RTI for %d: %d", fHeader.Time[0], RTI_ko);
1720  }
1721  } // once per second
1722 
1723 #ifdef PREDICT
1724  LonPred=(Double_t)((iss.Lon<180)?iss.Lon:(iss.Lon-360));
1725  LatPred=(Double_t)(iss.Lat);
1726  AltPred=(Double_t)(iss.Alt);
1727  // printf("(LatPred, LonPred, AltPred) = (%f, %f, %f)\n", LatPred, LonPred, AltPred); //only for debug
1728 #endif
1729 #ifdef CGM
1730  // LonCGM=(Double_t)((cgm.clor<180)?cgm.clor:(cgm.clor-360));
1731  LonCGM=M_PI*(Double_t)(cgm.clor)/180.0;
1732  LatCGM=M_PI*(Double_t)(cgm.clar)/180.0;
1733  RadCGM=((Double_t)(cgm.rbm));
1734  // printf("(LatCGM, LonCGM, AltCGM) = (%f, %f, %f)\n", LatCGM, LonCGM, RadCGM); //only for debug
1735  // printf("CGM radius (~ L) = %f -> %f km\n", cgm.rbm, EARTHRADIUS*RadCGM); //only for debug
1736 #endif
1737 #ifdef FIELD
1738  Field=geomag.F;
1739 #endif
1740 
1741  if (setup) {
1742  if (fHeader.Time[0] != TimePrevSlow) {
1743  TimePrevSlow = fHeader.Time[0];
1744  slowcontrol = &(setup->fSlowControl);
1745 #ifdef SLOWCONTROLTEMP
1746  std::vector<float> temp;
1747  slowcontrol->GetData("Sensor A", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1748  if (temp.size()>0) SensorA = temp[0];
1749  slowcontrol->GetData("Sensor C", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1750  if (temp.size()>0) SensorC = temp[0];
1751  slowcontrol->GetData("Sensor K", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1752  if (temp.size()>0) SensorK = temp[0];
1753  slowcontrol->GetData("Sensor L", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1754  if (temp.size()>0) SensorL = temp[0];
1755  slowcontrol->GetData("Sensor M", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1756  if (temp.size()>0) SensorM = temp[0];
1757  slowcontrol->GetData("M-7X 0 1N-1", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1758  if (temp.size()>0) Plane1N_M70 = temp[0];
1759  slowcontrol->GetData("M-7X 0 1N-2", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1760  if (temp.size()>0) Plane1N_M71 = temp[0];
1761  slowcontrol->GetData("M-7X 0 1N-3", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1762  if (temp.size()>0) Plane1N_M72 = temp[0];
1763  slowcontrol->GetData("M-7X 0 1N-4", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1764  if (temp.size()>0) Plane1N_M73 = temp[0];
1765  slowcontrol->GetData("Sensor 8", fHeader.Time[0], (float)(fHeader.Time[1]/1000000.0), temp);
1766  if (temp.size()>0) Sensor8 = temp[0];
1767 #endif
1768  }
1769  }
1770 
1771  if (daqev) {
1772  Lenght=daqev->Length;
1773  Tdr=daqev->Tdr;
1774  Udr=daqev->Udr;
1775  Sdr=daqev->Sdr;
1776  Rdr=daqev->Rdr;
1777  Edr=daqev->Edr;
1778  L1dr=daqev->L1dr;
1779  L3dr=daqev->L3dr;
1780  L3Error=daqev->L3Error;
1781  L3VEvent=daqev->L3VEvent;
1782  L3TimeD=daqev->L3TimeD;
1783 #if !defined _B524_ && !defined _B550_
1784  copy_n( daqev->JINJStatus, 4, JINJStatus);
1785  copy_n( daqev->JError, 24, JError);
1786 #endif
1787  }
1788 
1789 #if defined(DSPERRORS) && !defined _B524_ && !defined _B550_ && !defined _B572_
1790  pdsperr=head->pDSPError();
1791 #endif
1792 
1793  }
1794 
1795  //------------------------------------------------------------------------------------------------------------------------
1796 
1797  PRINTDEBUG;
1798 
1799  //--------------------------LVL1 & TOF-----------------------------
1800  if (lvl1) {
1801 
1802  EcalFlag = lvl1->EcalFlag;
1803  copy_n( lvl1->TrigRates, 19,TrigRates);
1804  copy_n( lvl1->TofPatt1, 4 ,TofPatt1);
1805  copy_n( lvl1->TofPatt2, 4 ,TofPatt2);
1806  JMembPatt = lvl1->JMembPatt;
1807  PhysBPatt=lvl1->PhysBPatt;
1808  PhysBPattPhys=PhysBPatt&0x3E;//(physbpatt&0x3E) is the "physic" part of PhysBPatt (from bit 1 to bit 5)
1809  lvl1->RestorePhysBPat();
1810  PhysBPattRestored=lvl1->PhysBPatt;
1811  TofFlag1 = lvl1->TofFlag1;
1812  TofFlag2 = lvl1->TofFlag2;
1813  LiveTime = lvl1->LiveTime;
1814  DeltaT = lvl1->TrigTime[4]; // in musec
1815  Lvl1Time = 0.64*(lvl1->TrigTime[2] + pow(2.0, 32.0)*lvl1->TrigTime[3]);
1816  DeltaTMine = Lvl1Time - Lvl1TimePrevious;
1817  if (DeltaTMine<0) DeltaTMine = Lvl1Time - (Lvl1TimePrevious - lvl1->TrigTime[0]*0.64);
1818  // printf("%d) DeltaT = %u - DeltaTMine = %f - Diff = %E\n", Event, DeltaT, DeltaTMine, DeltaT-DeltaTMine);
1819  // printf("%u %u %u %u %u\n", lvl1->TrigTime[0], lvl1->TrigTime[1], lvl1->TrigTime[2], lvl1->TrigTime[3], lvl1->TrigTime[4]);
1820  // printf("JMDCtime = %d,%06d, LVL1-time = %f\n", fHeader.Time[0], fHeader.Time[1], Lvl1Time);
1821  Lvl1TimePrevious = Lvl1Time;
1822 
1823  PRINTDEBUG;
1824 
1825  //--------------------------ANTI------------------------------
1826  AntiPatt=lvl1->AntiPatt;
1827  nAnti=0;
1828  for (int ii=0; ii<=8; ii++){
1829  if((AntiPatt)&(1<<ii)) {
1830  nAnti++;//counting the number of anti fired
1831  }
1832  }
1833 
1834  }
1835 
1836  PRINTDEBUG;
1837 
1838  nTofCluster=pev->nTofCluster();
1839  for (int ii=0; ii<nTofCluster; ii++) {
1840  TofClusterR* tfr=pev->pTofCluster(ii);
1841  if (((tfr->Layer)-1)>3) printf("nTofCluster evaluation: layer number (%d) not possible!\n", tfr->Layer);
1842  else nTofClusterL[(tfr->Layer)-1]++;
1843  }
1844 
1845  PRINTDEBUG;
1846 
1847  //--------------------------TRD------------------------------
1848  _nTrdTrack = pev->nTrdTrack();
1849  _nTrdCluster = pev->nTrdCluster();
1850  _nTrdRawHit = pev->nTrdRawHit();
1851  _nTrdSegment = pev->nTrdSegment();
1852 
1853  PRINTDEBUG;
1854 
1855  if(pev->nMCEventg()>0){
1856  //---------------------TRACKER----------------------------------
1857  _nTrTrack = pev->NTrTrack();
1858  _nTrCluster = pev->NTrCluster();
1859  _nTrRecHit = pev->NTrRecHit();
1860  _nTrRawCluster = pev->NTrRawCluster();
1861  //--------------------------ECAL------------------------------
1862  _nEcalShower = pev->NEcalShower();
1863 
1864  //--------------------------TOF-------------------------------
1865  _nBetaH = pev->NBetaH();
1866  // if(!nBetaH) TofRecH::ReBuild(); //reconstruct BetaHR object. This will also ReInit ParticleR and ChargeR AMSEventR
1867  _nBeta = pev->NBeta();
1868 
1869  //-------------------------RICH-------------------------------
1870  _nRichRing = pev->NRichRing();
1871  _nRichHit = pev->NRichHit();
1872 
1873  //-------------------------Particle---------------------------
1874  _nParticle = pev->NParticle();
1875  }
1876  else{
1877  //---------------------TRACKER----------------------------------
1878  _nTrTrack = pev->nTrTrack();
1879  _nTrCluster = pev->nTrCluster();
1880  _nTrRecHit = pev->nTrRecHit();
1881  _nTrRawCluster = pev->nTrRawCluster();
1882  //--------------------------ECAL------------------------------
1883  _nEcalShower = pev->nEcalShower();
1884 
1885  //--------------------------TOF-------------------------------
1886  _nBetaH = pev->nBetaH();
1887  // if(!nBetaH) TofRecH::ReBuild(); //reconstruct BetaHR object. This will also ReInit ParticleR and ChargeR AMSEventR
1888  _nBeta = pev->nBeta();
1889 
1890  //-------------------------RICH-------------------------------
1891  _nRichRing = pev->nRichRing();
1892  _nRichHit = pev->nRichHit();
1893 
1894  //-------------------------Particle---------------------------
1895  _nParticle = pev->nParticle();
1896  }
1897 
1898 
1899  for (int ii=0; ii<_nTrRawCluster; ii++) {
1900  static TrClusterR* clu;
1901  clu = pev->pTrCluster(ii);
1902  if (clu) {
1903  static int layer;
1904  layer = clu->GetLayer();
1905  // printf("Layer = %d\n", layer);//only for debug
1906  if ((layer-1)>8) printf("nTrRawCluster evaluation: layer number (%d) not possible!\n", layer);
1907  else _nTrRawClusterL[layer-1]++;
1908  }
1909  }
1910  tkrechitsevent = &(pev->TrRecHit());
1911 
1912  PRINTDEBUG;
1913 
1914  return;
1915 }
1916 
1917 
1918 // void myEventFiller::RebuildxLkTrk(myParticle& mp, myTrTrackPlus& mt, myEcalShower& me, myBetaPlus& mb){
1919 
1920 // TrkLHVar var1;
1921 // // printf("myEventFiller::RebuildLkTrk: ipart = %d\n", ipart);//only for debug
1922 // var1.btp = mt.gbpj; // bitpattern
1923 // var1.energy = me.EnergyE;
1924 // var1.rigidity_ch = mt.rigidity; // algo 1
1925 // var1.chiy_ch = pow(10, mt.logchisqY);
1926 // var1.chix_ch = pow(10, mt.logchisqX);
1927 // var1.err_ch = mt.sigmarinv_SameWeight; // same weigth algo 21
1928 // var1.rigidity_al = mt.rigidity_al; // algo 2
1929 // var1.rigidity_in = mt.rigidity_inn; // pattern 3
1930 // var1.rigidity_bt = mt.rigidity_k9; // pattern 6
1931 // var1.rigidity_tp = mt.rigidity_k8; // pattern 5
1932 // var1.rigidity_ibt = mt.rigidity_lh; // pattern 2
1933 // var1.rigidity_itp = mt.rigidity_uh; // pattern 1
1934 // var1.trkqin = mt.trackchargeinn; // inner trk ch
1935 // var1.trkqrms = mt.trackchargerms; // rms trk char
1936 // var1.minoise1 = mt.trnoisemindist[0].y();
1937 // var1.minoise2 = mt.trnoisemindist[1].y();
1938 // var1.minoise3 = mt.trnoisemindist[2].y();
1939 // var1.minoise4 = mt.trnoisemindist[3].y();
1940 // var1.nlayer = 0.0;
1941 // for (int layer=0; layer<=8; layer++) {
1942 // if((mt.gbpj)&(1<<layer))
1943 // var1.nlayer=var1.nlayer+1.0; // found number hitted layer
1944 // }
1945 // var1.tof_qd = mb.TofTrackChargePlaneLower;
1946 // var1.tof_qu = mb.TofTrackChargePlaneUpper;
1947 // var1.ntrk = 1.*(nTrTrack);
1948 // var1.nanti = 1.*(nanti);
1949 
1950 
1951 // // ECAL RELATED
1952 // //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1953 // myPoint ecalp9;//=PointTrackEntryEcal;
1954 // myPoint ecalp0;//=PointTrackExitEcal;
1955 // myPoint ecalCofG=mt.PointTrackCogEcal;
1956 
1957 // var1.ecal_ecogx = me.CofG[0];
1958 // var1.ecal_ecogy = me.CofG[1];
1959 // var1.trk_ecogx = ecalCofG.x();
1960 // var1.trk_ecogy = ecalCofG.y();
1961 // myDir dird=mt.DirTrackExitEcal;
1962 // var1.cosy = fabs(dird.y());
1963 
1964 // Double_t dzn = (me.Entry[2]);
1965 // Double_t dzx = (me.Exit[2]);
1966 // if (dzn*dzn < dzx*dzx) {// standard direction
1967 // ecalp9.setp(me.Entry[0], me.Entry[1], me.Entry[2]);
1968 // ecalp0.setp(me.Exit[0], me.Exit[1], me.Exit[2]);
1969 // }
1970 // else {// contrary direction
1971 // ecalp0.setp(me.Entry[0], me.Entry[1], me.Entry[2]);
1972 // ecalp9.setp(me.Exit[0], me.Exit[1], me.Exit[2]);
1973 // }
1974 // Double_t ecp9x = ecalp9.x();
1975 // Double_t ecp9y = ecalp9.y();
1976 // Double_t ecp9z = ecalp9.z();
1977 // Double_t ecp0x = ecalCofG.x();
1978 // Double_t ecp0y = ecalCofG.y();
1979 // Double_t ecp0z = ecalCofG.z();
1980 // Double_t tecdx = dird.x();
1981 // Double_t tecdy = dird.y();
1982 // Double_t tecdz = dird.z();
1983 
1984 // Double_t norm1 = (ecp9x-ecp0x)*(ecp9x-ecp0x)+(ecp9y-ecp0y)*(ecp9y-ecp0y)+(ecp9z-ecp0z)*(ecp9z-ecp0z);
1985 // norm1 = sqrt(norm1);
1986 // Double_t norm2 = sqrt(tecdx*tecdx+tecdy*tecdy+tecdz*tecdz);
1987 // Double_t coset = (ecp9x-ecp0x)*tecdx+(ecp9y-ecp0y)*tecdy+(ecp9z-ecp0z)*tecdz;
1988 // coset = fabs(coset)/(norm1*norm2);
1989 // coset = fabs(1.-coset*coset); // is sinsquare trk-ecal
1990 // var1.sinq_trk_ecal = coset;
1991 // var1.sinq_trk_trd = 0; // to be done and understood MC reliability of TRD track
1992 // //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1993 
1994 // int nm = TrkLH::gethead()->fillvar(var1);
1995 // if (nm!=0) cout << " error var filling " << nm << endl;
1996 // // cout << " var filled " << endl;
1997 // mt.lktrk = TrkLH::gethead()->dotrklk(var1.energy, var1.pat); // var1.pat e' il pattern
1998 // // printf("lktrk = %f\n", lktrk);
1999 // }
2000 
2001 #endif
2002 
2003 #ifdef _WITHGBATCH_
2004 
2005 int TRDWeakForEPSeparation(AMSEventR* pev){
2006 
2007  if (!pev) return 2;
2008 
2009  string reason = "";
2010  if (AMSEventR::getsetup())
2011  AMSEventR::getsetup()->IsBadRun(reason, pev->UTime(), pev->Run());
2012  else
2013  return 2;//cannot access to setup
2014 
2015  // if (tag==1) cout << "Reason = " << reason << endl;//only for debug
2016 
2017  // if the run is only "weak" for EP separation (example: circulation of gas after refill) but not "bad" or "unusable" accept it
2018  if (reason.find("TRD_WeakForEPseparation") != string::npos && reason.find("TRD_BadForEPseparation") == string::npos && reason.find("TRD_UnusableForAnalysis") == string::npos)
2019  return 0;//weak for ep separation
2020 
2021  return 1;//other
2022 }
2023 
2024 int TrdRunCategory( AMSEventR* pev ){
2025 
2026  if (!pev) return -1;
2027 
2028  string reason = "";
2029  if (AMSEventR::getsetup())
2030  AMSEventR::getsetup()->IsBadRun(reason, pev->UTime(), pev->Run());
2031  else
2032  return -1;//cannot access to setup
2033 
2034  bool weak = ( reason.find("TRD_WeakForEPseparation") != string::npos );
2035  bool bad = ( reason.find("TRD_BadForEPseparation") != string::npos );
2036  bool unusab = ( reason.find("TRD_UnusableForAnalysis") != string::npos );
2037 
2038  if ( weak && !bad && !unusab ) return 1;// TRD catB
2039  if ( bad && !unusab ) return 2;// TRD catC
2040  if ( unusab ) return 3;// TRD catD
2041 
2042  return 0;//TRD catA
2043 }
2044 
2045 bool BadRunCheck(AMSEventR *pev){
2046 
2047  if (!pev) return false;//return false to have the cutnotpassed evaluated more reasonably
2048 
2049  int tag = pev->IsBadRun("");
2050 
2051  if(tag==0) return false; //good run
2052  else if(tag==1) return true; //bad run
2053  else if(tag==2) {
2054  printf("Run:%d Ev:%d -> Cannot acces to root_setup. Skipping this event\n", (int)pev->Run(), (int)pev->Event());
2055  return true;
2056  }
2057  return true; //default
2058 }
2059 
2060 int IsScienceRun(AMSEventR *pev){
2061 
2062  if(!pev) return -1;//return true to have the cutnotpassed evaluated more reasonably
2063 
2064  // Science runtag
2065  HeaderR* header = &(pev->fHeader);
2066  if (!header) return -1;//return true to have the cutnotpassed evaluated more reasonably
2067 
2068  if (header->RunType>=0xF000) return 1; //faster than: if ((header->RunType >> 12) != 0xf) return true;
2069  else {
2070  if (header->RunType>=0xED0D) return 2; //to include TrdRefill
2071  else if (header->RunType==0xD53C) return 2; //to include TrdRefill
2072  else if (header->RunType>=0xD510 && header->RunType<=0xD51A) return 2;//to include TrdRefill
2073  }
2074  return 0;
2075 }
2076 
2077 int RunAnalysisCategory(AMSEventR *pev){
2078 
2079  //************
2080  //This function returns the category of a run
2081  //return 0: ''GOLDEN'' is not in the bad run list and has the SCI run flag
2082  //return 1: ''SILVER'' is in the bad run list and has the SCI run flag OR without SCI run flag but TRD-usable
2083  //return -1: ''NOT USABLE'' run is not SCI or not usable for TRD, so should not be used in the analysis
2084  //************
2085 
2086  //check if the run is "NotUsable" for TRD
2087  int trd_cat = TrdRunCategory(pev);
2088  bool trd_unusable = (trd_cat==3);
2089 
2090  //check if the run is a "science run" --- consider TrdRefills periods as science runs
2091  int runtag_cat = IsScienceRun(pev);
2092  bool sci = (runtag_cat==1 || runtag_cat==2);
2093 
2094  //check if the run is in the bad run list
2095  //this includes also trd refills runs (however the 'unusable' are checked with the bool below)
2096  bool bad = (BadRunCheck(pev) || runtag_cat==2);
2097 
2098  int tag=-1;//this will be returned if !sci
2099  if (trd_unusable) return -1;
2100  else if (sci) {
2101  if (bad) tag=1;
2102  else tag=0;
2103  }
2104  return tag;
2105 }
2106 
2107 #endif
2108 
2109 int myEvent::RebuildTrigPatt(int &L1TrMemPatt,int &PhysTrPatt){
2110  //cout<<"Rebuild event...."<<endl;
2111  //returns: two new trig-patterns and int. flag 0/1->"WasOnlyUnbiasedTrig"/"WasPhysTrig"
2112 
2113  L1TrMemPatt=0;
2114  PhysTrPatt=0;
2115  int TrigPatt(0),PhysTrigPatt(0);
2116  int tofpattft[4]={0,0,0,0};
2117  int tofpattbz[4]={0,0,0,0};
2118  int AccPatt(0),NAccs(0);
2119  int TOFTrigFl1(-1),TOFTrigFl2(-1),ECTrigFl(-1);
2120  bool FTZ(0);
2121 
2122  int PhysTrSet[8]={0,0,0,0,0,0,0,0};
2123  PhysTrSet[0]=(1<<1);//ch_unb:FTCP0
2124  PhysTrSet[1]=(1<<4)+(1<<7);//singl_charged(not el):FTCT1&ACC
2125  PhysTrSet[2]=(1<<8)+(1<<9);//ions:ACC1&BZ
2126  PhysTrSet[3]=(1<<5);//sl_ions:FTZ
2127  PhysTrSet[4]=(1<<4)+(1<<10);//el:FTCT1&EC-F_and
2128  PhysTrSet[5]=(1<<12);//ph:EC-A_and
2129  PhysTrSet[6]=(1<<11);//unbEC:EC-A_or
2130 
2131  //------> get current trig. parameters:
2132  for(int ii=0;ii<4;ii++){
2133  // tofpattft[ii]=me->TofPatt1[ii];
2134  // tofpattbz[ii]=me->TofPatt2[ii];
2135  tofpattft[ii]=TofPatt1[ii];
2136  tofpattbz[ii]=TofPatt2[ii];
2137  }
2138 
2139  // TrigPatt=me->JMembPatt;
2140  //PhysTrigPatt=me->PhysBPatt;
2141  TrigPatt=JMembPatt;
2142  PhysTrigPatt=PhysBPatt;
2143  FTZ=((TrigPatt&(1<<5))!=0);
2144 
2145  //AccPatt=me->AntiPatt;
2146  //TOFTrigFl1=me->TofFlag1;
2147  //TOFTrigFl2=me->TofFlag2;
2148  //ECTrigFl=me->EcalFlag;
2149 
2150  AccPatt=AntiPatt;
2151  TOFTrigFl1=TofFlag1;
2152  TOFTrigFl2=TofFlag2;
2153  ECTrigFl=EcalFlag;
2154  // N=0/1/2/3-> /undef/noLev1/Lev1or/Lev1and
2155 
2156 bool CentrOK=((tofpattft[2]&0x1FE01FEL)>0);//have any central counter in Lay-3 trig.patt
2157 
2158 //-----------------------------------------
2159 
2160 //------>FTC,FTCP0,FTCP1 rebuild:
2161 //
2162  if(TOFTrigFl1<=4 && TOFTrigFl1>=0){
2163  L1TrMemPatt|=(1<<1);// set FTCP0(>=3of4)
2164  L1TrMemPatt|=1;// set FTC
2165  }
2166 
2167  if(TOFTrigFl1==0)L1TrMemPatt|=(1<<2);// set FTCP1(4of4)
2168  //-----------------------------------------
2169  //------>FTCT1 rebuild:
2170  //
2171  if(TOFTrigFl1==0 && CentrOK){//was tof 4of4
2172  L1TrMemPatt|=(1<<4);// set FTCT1
2173  }
2174  //-----------------------------------------
2175  //------> ACC0/1 rebuild:
2176  //
2177  for(int i=0;i<8;i++)if((AccPatt & (1<<i))>0)NAccs+=1;//count nsectors
2178  if(NAccs<1)L1TrMemPatt|=(1<<7);// set ACC0
2179  if(NAccs<5)L1TrMemPatt|=(1<<8);// set ACC1
2180  //-----------------------------------------
2181  //------> FTZ,BZ-bits rebuild(no need to exclude out.c in L3):
2182  //
2183  if(FTZ)L1TrMemPatt|=(1<<5);// set FTZ as it was
2184  if(TOFTrigFl2==0)L1TrMemPatt|=(1<<9);// set BZ "4of4"
2185  //-----------------------------------------
2186  //------> EC-bits rebuild:
2187  //
2188  if((ECTrigFl/10)==3){
2189  L1TrMemPatt|=(1<<10);// set EC-F_and
2190  L1TrMemPatt|=(1<<11);// set EC-F_or
2191  }
2192  else if((ECTrigFl/10==1) || (ECTrigFl/10==2))L1TrMemPatt|=(1<<11);// set EC-F_or
2193  if(ECTrigFl%10>=2){
2194  // L1TrMemPatt|=(1<<13);// set EC-A_or
2195  if(ECTrigFl%10==3)L1TrMemPatt|=(1<<12);// set EC-A_and
2196  }
2197  if((L1TrMemPatt&(1<<11))>0)L1TrMemPatt|=(1<<6);// set FTE (EC-F_or is required)
2198  //-----------------------------------------
2199  //------>rebuild PhysTrigPatt:
2200  //
2201  for(int i=0;i<7;i++){
2202  if((L1TrMemPatt&PhysTrSet[i])==PhysTrSet[i])PhysTrPatt|=(1<<i);
2203  }
2204  //-----------------------------------------
2205 
2206  if((PhysTrPatt&0x3EL)>0)return 1;
2207  else return 0;
2208 }