00001
00002
00003
00004
00005
00007
00008
00009 #include "AlEvent.h"
00010 #include "TimeInfo.h"
00011 #include "mt19937-1.h"
00012 #include "fortran_def.h"
00013 #include <math.h>
00014 #include <string.h>
00015
00016
00017 AlEvent::AlEvent() {}
00018
00019
00020 AlEvent::AlEvent(const AlEvent& oldEvent) {
00021 qhac = oldEvent.qhac;
00022 }
00023
00024
00025 int AlEvent::SIsetup=-1;
00026 int AlEvent::mask1 = 0;
00027 int AlEvent::mask2 = 0;
00028 int AlEvent::mask3 = 0;
00029 int AlEvent::tmask = 0;
00030
00031 EVEH* AlEvent::Header()const{return qhac->EH;}
00032 KEVH* AlEvent::GeneratorStatus() const{return qhac->KE;}
00033 REVH* AlEvent::ReconstructorHeader() const{return qhac->RE;}
00034 vector<LOLE*>* AlEvent::LcalErrorFlags() const{return &(qhac->LO);}
00035 vector<X1RG*>* AlEvent::Readout() const{return &(qhac->X1);}
00036 BOMB* AlEvent::BeamPosition() const{return qhac->BO;}
00037 vector<XTBN*>* AlEvent::TriggerBitNames() const{return &(qhac->BN);}
00038 XTCN* AlEvent::TriggerLevelControl() const{return qhac->CN;}
00039 XTOP* AlEvent::TriggerOptions()const{return qhac->OP;}
00040 LUPA* AlEvent::LuminosityParameters()const{return qhac->LP;}
00041 SILH* AlEvent::SicalLuminosityParameters()const{return qhac->SI;}
00042 vector<XHVB*>* AlEvent::HVfixes()const{return &(qhac->HV);}
00043 XTEB* AlEvent::TriggerLevelEventBitPattern()const{return qhac->EB;}
00044 XTRB* AlEvent::TriggerLevelRegisterBitPattern()const{return qhac->RB;}
00045 DTBP* AlEvent::TriggerBitPattern()const{return qhac->BP;}
00046 vector<VHBV*>* AlEvent::VDETbit()const{return &(qhac->BV);}
00047 vector<VHPV*>* AlEvent::NoHVbit()const{return &(qhac->PV);}
00048 EAUX* AlEvent::ENFLWinfo()const{return qhac->EX;}
00049 SIX2* AlEvent::SicalTriggerX2()const{return qhac->X2;}
00050 vector<X1TV*>* AlEvent::Triggerlevel1Threshold()const{return &(qhac->TV);}
00051 vector<KWGT*>* AlEvent::GeneratorWeights() const{return &(qhac->KW);}
00052 vector<X1IP*>* AlEvent::Triggerlevel1Input()const{return &(qhac->IP);}
00053 vector<SIXA*>* AlEvent::SicalTriggerSectorsAdc()const{return &(qhac->XA);}
00054 SITC* AlEvent::SicalTriggerConditions()const{return qhac->TC;}
00055 vector<SRCO*>* AlEvent::SicalRunConditions()const{return &(qhac->CO);}
00056 vector<X1TH*>* AlEvent::TriggerOldlevel1Threshold()const{return &(qhac->TH);}
00057 vector<X1AD*>* AlEvent::Triggerlevel1Adc()const{return &(qhac->XD);}
00058
00059 void AlEvent::SETqhac(QHAC* bank) {qhac = bank;}
00060
00061
00062 TimeInfo AlEvent::Time()const
00063 {
00064 if (qhac->EH != (EVEH*) NULL)
00065 {
00066 TimeInfo summary(qhac->EH->DA,qhac->EH->TI);
00067 return summary;
00068 }
00069 else
00070 {
00071 TimeInfo summary;
00072 summary.sec = -1;
00073 summary.min = -1;
00074 summary.hour = -1;
00075 summary.day = -1;
00076 summary.month = -1;
00077 summary.year = -1;
00078 return summary;
00079 }
00080 }
00081
00082
00083 int AlEvent::number()const
00084 {
00085 if (qhac->EH != (EVEH*) NULL)
00086 return qhac->EH->EV;
00087 else
00088 return -1;
00089 }
00090
00091
00092 int AlEvent::type()const
00093 {
00094 if (qhac->EH != (EVEH*) NULL)
00095 return qhac->EH->TY;
00096 else
00097 return -1;
00098 }
00099
00100
00101 int AlEvent::EdirClass()const
00102 {
00103 if (qhac->RE != (REVH*) NULL)
00104 return qhac->RE->EC;
00105 else
00106 return 0;
00107 }
00108
00109
00110 int AlEvent::ErrorStatus()const
00111 {
00112 if (qhac->EH != (EVEH*) NULL)
00113 return qhac->EH->ES;
00114 else
00115 return -1;
00116 }
00117
00118
00119 float AlEvent::Energy()const
00120 {
00121 if (qhac->EH != (EVEH*) NULL)
00122 return (float(qhac->EH->TE))/1000000.;
00123 else
00124 return -1;
00125
00126
00127
00128
00129
00130 }
00131
00132
00133 float AlEvent::gen_e12(float qelep)const
00134 {
00135 float e12;
00136 if (qelep<180)
00137 e12=0;
00138 else if (qelep<185)
00139 if (genrand()>0.046) e12=0;
00140 else {float y; do { e12=genrand()*70; y=genrand()*700;}
00141 while (y > r183_e12(e12));}
00142 else if (qelep<190)
00143 e12=e12_produce(0.08736,3.,3.3,1200.,qelep,&AlEvent::r189_e12);
00144 else if (qelep<194)
00145 e12=e12_produce(0.08761,3.,3.35,300.,qelep,&AlEvent::r192_e12);
00146 else if (qelep<198)
00147 e12=e12_produce(0.09738,3.,3.35,600.,qelep,&AlEvent::r196_e12);
00148 else if (qelep<201)
00149 e12=e12_produce(0.08761,3.,3.35,600.,qelep,&AlEvent::r200_e12);
00150 else if (qelep<203)
00151 e12=e12_produce(0.07973,3.,3.35,300.,qelep,&AlEvent::r202_e12);
00152 else if (qelep<206)
00153 e12=e12_produce(0.09497,3.,3.35,700,qelep,&AlEvent::r205_e12);
00154 else e12=e12_produce(0.08784,3.,3.35,1000,qelep,&AlEvent::r207_e12);
00155 return e12;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165 bool AlEvent::xlumok(float qelep, int mode)const
00166 {
00167
00168 static int lastrun = 0;
00169 static int xtgenb = 0;
00170 if (qhac->AD != (ADBR*)NULL) SIsetup = qhac->AD->SI;
00171 if (SIsetup < 0) return false;
00172 int runnum;
00173 if ((qhac->EH) != (EVEH*) NULL)
00174 runnum = qhac->EH->RN;
00175 else return false;
00176
00177 if (runnum < 2001) return ( (SIsetup >= 0) && VDETstatus() );
00178
00179 if (runnum != lastrun) {lastrun=runnum; xtgenb = EnabledTriggers();}
00180 else if (xtgenb < 4) xtgenb = EnabledTriggers();
00181
00182 if (LaserEvent()) return false;
00183
00184 vector<bool> XHV = HVStatus();
00185 bool XHVTR = XHV[15] && XHV[5];
00186 bool XHVE = XHV[0] && XHV[1] && XHV[2];
00187 bool XHVH = XHV[7] && XHV[8] && XHV[9];
00188 bool XHVTG = XHV[13] && XHV[14];
00189 bool XHVOK = XHVTR && XHVE && XHVH && XHVTG;
00190 bool XHVL = XHV[3];
00191 bool XHVS = XHV[10];
00192
00193 bool XT0 = TimeSynchronization();
00194
00195 bool LL = (SIsetup>=6) && XHVOK && XHVL && XT0;
00196 bool SL = ((SIsetup==5)||(SIsetup==7)) && XHVOK && XHVS && XT0;
00197 if ((runnum>20000)&&(runnum<40000)) LL = (SIsetup>=4) && XHVOK && XHVL && XT0;
00198 if (runnum>40000) SL = (SIsetup>=4) && XHVOK && XHVS && XT0;
00199 bool XL = LL && ( SL || (SIsetup==0));
00200 if (runnum > 45000) XL = ( XL && VDETstatus() );
00201 if (mode == 0)
00202 return (XL && EnergyStability(qelep));
00203 else if (mode == 1)
00204 return XL;
00205 else if (mode == 2)
00206 return (XL && !EnergyStability(qelep));
00207 else return 0;
00208 }
00209
00210
00211
00212
00213 bool AlEvent::IsTrigger(bool MINI)const
00214 {
00215 int pattern=0;
00216 int runnum;
00217 if ((qhac->EH) != (EVEH*) NULL)
00218 runnum = qhac->EH->RN;
00219 else
00220 runnum = -1;
00221 if( MINI && (ENFLWinfo() != NULL)) pattern = ENFLWinfo()->TR;
00222 else
00223 {
00224 if (runnum < 4000)
00225 {
00226 if (Readout() != NULL) RedoTrigger();
00227 else RedoOldTrigger();
00228 }
00229 pattern = GetRawTrigger();
00230 }
00231
00232
00233
00234 int itrg1 = 8*((pattern>>17)&1) + ((pattern>>20)&1);
00235
00236 itrg1 += 2*((pattern>>(((runnum<6000)&&(Readout()->size()==0))?24:18))&1);
00237 itrg1 += 4*((pattern>>(((runnum<6000)&&(Readout()->size()==0))?25:19))&1);
00238
00239 int itrg2 = ((pattern>>8)&1) + 2*((pattern>>9)&1);
00240
00241 return ((itrg1!=0)||(itrg2!=0));
00242 }
00243
00244
00245 int AlEvent::GetRawTrigger()const
00246 {
00247 int pattern;
00248 if(Readout()->size() != 0)
00249 {
00250 for(vector<X1RG*>::iterator iter=Readout()->begin();iter<Readout()->end();iter++)
00251 {
00252 char tmp[5];
00253 strncpy(tmp,(*iter)->NA,4);
00254 tmp[4] = '\0';
00255 if ((strcasecmp(tmp, "TPR ") == 0 )|| (strcasecmp(tmp, " RPT") == 0 ))
00256 pattern = ((*iter)->CO[0]);
00257 }
00258 }
00259 else if(TriggerLevelRegisterBitPattern() != NULL)
00260 pattern = TriggerLevelRegisterBitPattern()->RP[0];
00261 else if(TriggerLevelEventBitPattern() != NULL)
00262 pattern = TriggerLevelEventBitPattern()->T1;
00263 else if(TriggerBitPattern() != NULL)
00264 pattern = TriggerBitPattern()->T1;
00265 else if(LuminosityParameters() != NULL)
00266 pattern = LuminosityParameters()->T1;
00267 else if(SicalLuminosityParameters() != NULL)
00268 pattern = SicalLuminosityParameters()->T1;
00269 else pattern = 0;
00270 return pattern;
00271 }
00272
00273
00274
00275 float AlEvent::e12_produce(double thr, double c1, double c2, double c3, float qelep, float (AlEvent::*fp)(float x1)const)const
00276 {
00277 float x1,y;
00278 y=genrand();
00279 if (y>thr) return 0;
00280 do
00281 {
00282 x1=genrand()*c1-c2;
00283 y=genrand()*c3;
00284 }
00285 while (y > (this->*fp)(x1));
00286 return pow(10,x1)*qelep;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295 float AlEvent::r183_e12(float x1)const
00296 {
00297 float r183;
00298 if ( x1 < 0.4 ) r183 = 605.*exp(-pow((x1-0.34),2)/0.03);
00299 else if ( x1 < 3. ) r183 = 997.*(1.-exp(-5.*x1))*exp(-1.18*x1);
00300 else if ( x1 < 70. ) r183 = 270.*exp(-0.73*x1)+2.4-0.02*x1 ;
00301 else r183 = -999.;
00302 return r183;
00303 }
00304
00305
00306
00307
00308
00309
00310 float AlEvent::r189_e12(float xl)const
00311 {
00312 float r189;
00313 r189 = exp(-70.6-22.74*xl);
00314 r189 += 416.*exp(-0.5*pow(((xl+2.696)/0.1617),2));
00315 r189 += 1119.*exp(-0.5*pow(((xl+2.254)/0.3535),2));
00316 r189 += 188.*exp(-0.5*pow(((xl+1.030)/0.2688),2));
00317 r189 += 397.*exp(-0.5*pow(((xl+0.526)/0.0552),2));
00318 return r189;
00319 }
00320
00321
00322
00323
00324
00325
00326 float AlEvent::r192_e12(float xl)const
00327 {
00328 float r192;
00329 r192 = exp(-324.-98.*xl);
00330 r192 += 51.*exp(-0.5*pow(((xl+2.699)/0.1000),2));
00331 r192 += 213.*exp(-0.5*pow(((xl+2.354)/0.3502),2));
00332 r192 += 15.*exp(-0.5*pow(((xl+1.085)/0.3289),2));
00333 r192 += 89.*exp(-0.5*pow(((xl+0.513)/0.0460),2));
00334 return r192;
00335 }
00336
00337
00338
00339
00340
00341
00342 float AlEvent::r196_e12(float xl)const
00343 {
00344 float r196;
00345 r196 = exp(-323.-98.*xl);
00346 r196 += 81.*exp(-0.5*pow(((xl+2.757)/0.0816),2));
00347 r196 += 480.*exp(-0.5*pow(((xl+2.354)/0.3451),2));
00348 r196 += 16.*exp(-0.5*pow(((xl+1.027)/0.3257),2));
00349 r196 += 101.*exp(-0.5*pow(((xl+0.518)/0.0483),2));
00350 return r196;
00351 }
00352
00353
00354
00355
00356
00357
00358 float AlEvent::r200_e12(float xl)const
00359 {
00360 float r200;
00361 r200 = exp(-322.-98.*xl);
00362 r200 += 73.*exp(-0.5*pow(((xl+2.732)/0.0833),2));
00363 r200 += 519.*exp(-0.5*pow(((xl+2.362)/0.3446),2));
00364 r200 += 14.*exp(-0.5*pow(((xl+0.538)/0.8125),2));
00365 r200 += 106.*exp(-0.5*pow(((xl+0.492)/0.0554),2));
00366 return r200;
00367 }
00368
00369
00370
00371
00372
00373
00374 float AlEvent::r202_e12(float xl)const
00375 {
00376 float r202;
00377 r202 = exp(-322.-98.*xl);
00378 r202 += 41.*exp(-0.5*pow(((xl+2.794)/0.1261),2));
00379 r202 += 231.*exp(-0.5*pow(((xl+2.359)/0.3320),2));
00380 r202 += 3.*exp(-0.5*pow(((xl+1.507)/3.4067),2));
00381 r202 += 36.*exp(-0.5*pow(((xl+0.493)/0.0465),2));
00382 return r202;
00383 }
00384
00385
00386
00387
00388
00389
00390 float AlEvent::r205_e12(float xl)const
00391 {
00392 float r205;
00393 r205 = exp(-323.-98.*xl);
00394 r205 += 351.*exp(-0.5*pow(((xl+2.735)/0.1053),2));
00395 r205 += 535.*exp(-0.5*pow(((xl+2.337)/0.3496),2));
00396 r205 += 39.*exp(-0.5*pow(((xl+1.019)/0.2566),2));
00397 r205 += 156.*exp(-0.5*pow(((xl+0.483)/0.0390),2));
00398 return r205;
00399 }
00400
00401
00402
00403
00404
00405
00406 float AlEvent::r207_e12(float xl)const
00407 {
00408 float r207;
00409 r207 = exp(-322.-98.*xl);
00410 r207 += 553.*exp(-0.5*pow(((xl+2.739)/0.1078),2));
00411 r207 += 819.*exp(-0.5*pow(((xl+2.345)/0.3472),2));
00412 r207 += 60.*exp(-0.5*pow(((xl+1.026)/0.2712),2));
00413 r207 += 205.*exp(-0.5*pow(((xl+0.487)/0.0395),2));
00414 return r207;
00415 }
00416
00417
00418
00419
00420 bool AlEvent::EnergyStability(float qelep)const
00421 {
00422 int run2k=53000;
00423 int runnumber;
00424 if ((qhac->EH) != (EVEH*) NULL)
00425 runnumber = qhac->EH->RN;
00426 else
00427 runnumber = -1;
00428 if (runnumber<run2k) return true;
00429 if (qelep<110) return true;
00430 if (Readout()->size()>1)
00431 { if ((*Readout())[1] != NULL) return (((*Readout())[1]->CO[2])>>17)&1;
00432 else if (TriggerLevelControl() != NULL) return ((TriggerLevelControl()->TR[0])>>17)&1;
00433 else if (ReconstructorHeader() != NULL) return ((ReconstructorHeader()->DS)>>17)&1;
00434 else if (LuminosityParameters() != NULL) return ((LuminosityParameters()->HV)>>17)&1;
00435 else if (SicalLuminosityParameters() != NULL) return ((SicalLuminosityParameters()->HV)>>17)&1;
00436 else return false;
00437 }
00438 else if (TriggerLevelControl() != NULL) return ((TriggerLevelControl()->TR[0])>>17)&1;
00439 else if (ReconstructorHeader() != NULL) return ((ReconstructorHeader()->DS)>>17)&1;
00440 else if (LuminosityParameters() != NULL) return ((LuminosityParameters()->HV)>>17)&1;
00441 else if (SicalLuminosityParameters() != NULL) return ((SicalLuminosityParameters()->HV)>>17)&1;
00442 else return false;
00443 }
00444
00445
00446
00447
00448
00449 int AlEvent::EnabledTriggers()const
00450 {
00451
00452 char TTREQ[7][6][9] = {{"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00453 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00454 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00455 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00456 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00457 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"},
00458 {"SNG_MUON","SNG_C_EM","ETT_EWBA","ETT_EWE*","ETT_EWEB"}};
00459
00460 char TTREL[7][2][9] = {{"LC_HI_LO","LC_LO_HI"},
00461 {"LC_HI_LO","LC_LO_HI"},
00462 {"LT_HI_LO","LT_LO_HI"},
00463 {"LW_ET_HI"," "},
00464 {"LW_ET_HI"," "},
00465 {"LW_ET_HI"," "},
00466 {"LW_LO_HI"," "}};
00467
00468 char TTRES[7][1][9] = {{" "},
00469 {" "},
00470 {" "},
00471 {" "},
00472 {"SICAL_ME"},
00473 {"SICAL_ME"},
00474 {"SICAL_ME"}};
00475
00476 int MHDRQ[7] = {51512064, 51512064, 1966848, 1966848, 1966848, 1966848, 1966848};
00477
00478 int MHDRL[7] = {49152, 49152, 49152, 65536, 65536, 64, 32};
00479
00480 int MHDRS[7] = { 0, 0, 0, 0, 16, 16, 16};
00481
00482 int MXBRN[19] = { 4017, 4067, 4351, 4387, 4476, 4525, 4530, 5112, 5329, 5373, 5852,
00483 7240, 8419, 8420, 8423, 8424, 12528, 12536, 12718};
00484 int MXBMK[19] = { -2083339265,-2083339265,-2083339274,-2083339266,-2083339266,
00485 -2083339266,-2083339266,-2095922177,-2095922177,-2095922177,
00486 51569663 ,-2145393668,-2011175940,-2011175940,-2011175940,
00487 -2011175940,-2009078786,-2009078786,-2009078786};
00488 int runnum;
00489 if ((qhac->EH) != (EVEH*) NULL)
00490 runnum = qhac->EH->RN;
00491 else
00492 return 0;
00493
00494 if (runnum < 2001) return 7;
00495
00496 int period;
00497 if (runnum <= 4535)
00498 period = 0;
00499 else if (runnum <= 5909)
00500 period = 1;
00501 else if (runnum <= 14000)
00502 period = 2;
00503 else if (runnum <= 16500)
00504 period = 3;
00505 else if (runnum <= 20000)
00506 period = 4;
00507 else if (runnum <= 40000)
00508 period = 5;
00509 else period = 6;
00510
00511
00512
00513 bool OK=true;
00514 if (TriggerBitNames()->size() > 0)
00515 {
00516 mask1=(mask2=(mask3=0));
00517 for (vector<XTBN*>::iterator iter=TriggerBitNames()->begin();iter<TriggerBitNames()->end();iter++)
00518 {
00519 int idef = (*iter)->TN;
00520 int inum = (*iter)->TB;
00521 if ((inum<0) || (inum>31)) {break; OK=false;}
00522 if ((idef != 0) && (inum != 31))
00523 {
00524 char MNM[9];
00525 strncpy(MNM,(*iter)->BM,8);
00526 MNM[8] = '\0';
00527 if (strcasecmp(MNM, " ") != 0 )
00528 {
00529
00530 for(int i=0;i<6;i++)
00531 if(strcasecmp(MNM,TTREQ[period][i]) == 0) mask1 |= (1<<inum);
00532 for(int i=0;i<2;i++)
00533 if(strcasecmp(MNM,TTREL[period][i]) == 0) mask2 |= (1<<inum);
00534 for(int i=0;i<1;i++)
00535 if(strcasecmp(MNM,TTRES[period][i]) == 0) mask3 |= (1<<inum);
00536 }
00537 }
00538 }
00539 }
00540 if ((mask1 == 0)||(!OK)) mask1 = MHDRQ[period];
00541 if ((mask2 == 0)||(!OK)) mask2 = MHDRL[period];
00542 if ((mask3 == 0)||(!OK)) mask3 = MHDRS[period];
00543
00544 int result = 0;
00545 int MKENB = 0;
00546 if (TriggerOptions() != NULL) MKENB = TriggerOptions()->TR;
00547 else if (Readout()->size() != 0) MKENB = ((*Readout())[0])->CO[2];
00548 else if (LuminosityParameters() != NULL) MKENB = LuminosityParameters()->TE;
00549 else if (SicalLuminosityParameters() != NULL) MKENB = SicalLuminosityParameters()->TE;
00550 for (int i=0;i<19;i++) if (runnum == MXBRN[i]) MKENB = MXBMK[i];
00551
00552
00553 if (mask1 != 0) result |= (mask1 == (mask1 & MKENB));
00554 if (mask2 != 0) result |= ((mask2 == (mask2 & MKENB))<<1);
00555 if (mask3 != 0) result |= ((mask3 == (mask3 & MKENB))<<2);
00556
00557
00558
00559
00560 if ((runnum >= 13191) && (runnum <= 13199)) result |= 2;
00561 return result;
00562 }
00563
00564
00565 vector<bool> AlEvent::HVStatus()const
00566 {
00567 int MTPHV[7] = {4316,4328,4350,4351,4357,4367,4371};
00568 int MTFEV[7] = { 1, 154,1320, 1, 121, 372, 1};
00569 int MTLEV[7] = {2080, 804,1576,9999,9999,9999, 251};
00570 vector<bool> result(24,true);
00571 vector<bool> verybad(24,false);
00572 int runnum;
00573 if ((qhac->EH) != (EVEH*) NULL)
00574 runnum = qhac->EH->RN;
00575 else return verybad;
00576 if (runnum < 2001) return result;
00577 int tmp = 0;
00578 if (Readout()->size()>1)
00579 { if ((*Readout())[1] != NULL) tmp = (*Readout())[1]->CO[2];
00580 else if (TriggerLevelControl() != NULL) tmp = TriggerLevelControl()->TR[0];
00581 else if (ReconstructorHeader() != NULL) tmp = ReconstructorHeader()->DS;
00582 else if (LuminosityParameters() != NULL) tmp = LuminosityParameters()->HV;
00583 else if (SicalLuminosityParameters() != NULL) tmp = SicalLuminosityParameters()->HV;
00584 }
00585 else if (TriggerLevelControl() != NULL) tmp = TriggerLevelControl()->TR[0];
00586 else if (ReconstructorHeader() != NULL) tmp = ReconstructorHeader()->DS;
00587 else if (LuminosityParameters() != NULL) tmp = LuminosityParameters()->HV;
00588 else if (SicalLuminosityParameters() != NULL) tmp = SicalLuminosityParameters()->HV;
00589 for (int i = 0; i<24;i++) result[i]= (tmp & (1<<i));
00590
00591
00592
00593
00594
00595
00596
00597 if ((runnum == 20600) && (number()>=2787)) result[5] = false;
00598
00599
00600
00601
00602 if (runnum <= 4800)
00603 {
00604 for(int i=0;i<7;i++)
00605 if (runnum == MTPHV[i])
00606 {
00607 result[4] = false;
00608 if ((number()>=MTFEV[i]) && (number()<=MTLEV[i]))
00609 {
00610 result[4] = true;
00611 break;
00612 }
00613 }
00614 result[15] = result[4];
00615 }
00616
00617
00618
00619
00620 if (runnum <= 4800) result[7]=(result[8]=(result[9]=true));
00621
00622
00623 if ((runnum == 20639)&&(number()<690)) result[7]=(result[8]=false);
00624
00625 if ((runnum == 23276)&&(number()>11459)) result[7]=(result[8]=(result[9]=false));
00626
00627
00628
00629
00630
00631
00632
00633 int LOLEWD = 1;
00634 if (LuminosityParameters() != NULL) LOLEWD = LuminosityParameters()->LO;
00635 else if (LcalErrorFlags()->size() != 0) LOLEWD = ((*LcalErrorFlags())[0])->ER;
00636 else if (SicalLuminosityParameters() != NULL) LOLEWD = SicalLuminosityParameters()->LO;
00637 if (runnum == 4107) LOLEWD = 0;
00638 if (runnum == 4530) result[3] = true;
00639 if ((runnum == 4981)||(runnum == 4982)) LOLEWD = 0;
00640 if ((runnum >=10606)&&(runnum <= 10611)) LOLEWD = 0;
00641
00642
00643
00644 if ((runnum >= 17766)&&(runnum <= 17781)) result[10] = false;
00645
00646
00647
00648 if ((runnum == 20170)&&(number()>=3700)) result[10] = false;
00649 if ((runnum == 20592)&&(number()<=1500)) result[10] = false;
00650 if ((runnum == 20619)&&(number()>=7200)) result[10] = false;
00651 if ((runnum == 20621)&&(number()<= 500)) result[10] = false;
00652 if (runnum == 20620) result[10] = false;
00653
00654
00655
00656
00657
00658
00659
00660 if (runnum <= 4800) result[13]=(result[14]=true);
00661 for(vector<XHVB*>::iterator iter=HVfixes()->begin();iter<HVfixes()->end();iter++)
00662 if ((runnum == (*iter)->RU)&&(number() >= (*iter)->FE)&&(number() <= (*iter)->LE))
00663 result[(*iter)->DE-1]=(*iter)->HV;
00664 return result;
00665 }
00666
00667 bool AlEvent::TimeSynchronization()const
00668 {
00669 int runnum;
00670 tmask = 0;
00671 if ((qhac->EH) != (EVEH*) NULL)
00672 runnum = qhac->EH->RN;
00673 else return false;
00674 if (runnum < 2001) return true;
00675 bool OK=true;
00676 if (TriggerBitNames()->size() > 0)
00677 {
00678 tmask = 0;
00679 for (vector<XTBN*>::iterator iter=TriggerBitNames()->begin();iter<TriggerBitNames()->end();iter++)
00680 {
00681 int idef = (*iter)->TN;
00682 int inum = (*iter)->TB;
00683 if ((inum<0) || (inum>31)) {break; OK=false;}
00684 if ((idef != 0) && (inum != 31))
00685 {
00686 char MNM[9];
00687 strncpy(MNM,(*iter)->BM,8);
00688 MNM[8] = '\0';
00689 if (strcasecmp(MNM, " ") != 0 )
00690 {
00691
00692 for(int i=0;i<6;i++)
00693 if(strcasecmp(MNM,"T0_SYNCH") == 0) tmask |= (1<<inum);
00694 }
00695 }
00696 }
00697 }
00698 if ((tmask == 0)||(!OK))
00699 {
00700 if (runnum > 17061) tmask = 2;
00701 if (runnum > 20000) tmask = 268435456;
00702 }
00703
00704
00705
00706 if (tmask != 0)
00707 {
00708 if(Readout()->size() != 0)
00709 {
00710 for(vector<X1RG*>::iterator iter=Readout()->begin();iter<Readout()->end();iter++)
00711 {
00712 char tmp[5];
00713 strncpy(tmp,(*iter)->NA,4);
00714 tmp[4] = '\0';
00715 if ((strcasecmp(tmp, "TPR ") == 0 )|| (strcasecmp(tmp, " RPT") == 0 ))
00716 if (runnum<20000) return (( tmask & ((*iter)->CO[0]) ) == tmask );
00717 else return (( tmask & ((*iter)->CO[0]) ) == 0 );
00718 }
00719 }
00720 else if(TriggerLevelRegisterBitPattern() != NULL)
00721 if (runnum<20000) return (( tmask & (TriggerLevelRegisterBitPattern()->RP[0]) ) == tmask );
00722 else return (( tmask & (TriggerLevelRegisterBitPattern()->RP[0]) ) == 0 );
00723 else if(TriggerLevelEventBitPattern() != NULL)
00724 if (runnum<20000) return (( tmask & (TriggerLevelEventBitPattern()->T1) ) == tmask );
00725 else return (( tmask & (TriggerLevelEventBitPattern()->T1) ) == 0 );
00726 else if(TriggerBitPattern() != NULL)
00727 if (runnum<20000) return (( tmask & (TriggerBitPattern()->T1) ) == tmask );
00728 else return (( tmask & (TriggerBitPattern()->T1) ) == 0 );
00729 else if(LuminosityParameters() != NULL)
00730 if (runnum<20000) return (( tmask & (LuminosityParameters()->T1) ) == tmask );
00731 else return (( tmask & (LuminosityParameters()->T1) ) == 0 );
00732 else if(SicalLuminosityParameters() != NULL)
00733 if (runnum<20000) return (( tmask & (SicalLuminosityParameters()->T1) ) == tmask );
00734 else return (( tmask & (SicalLuminosityParameters()->T1) ) == 0 );
00735 }
00736 return true;
00737 }
00738
00739
00740 bool AlEvent::LaserEvent()const
00741 {
00742
00743 const int runs[13]={40307,40316,40334,40345,40395,40395,
00744 40396,40396,40418,40441,40471,40483,
00745 40512};
00746 const int events[13]={7214, 3398, 1542, 5064, 7511,13615,
00747 1993, 8630, 3126, 6159, 2751, 1596,
00748 1391};
00749 int runnum;
00750 if ((qhac->EH) != (EVEH*) NULL)
00751 runnum = qhac->EH->RN;
00752 else return false;
00753 if (((runnum < 40000) || (runnum > 40550))&& ((runnum < 25520) || (runnum > 25530))) return false;
00754 for(int i=0;i<13;i++)
00755 if ( (runnum == runs[i])&&(number() == events[i])) return true;
00756 if(Header() != NULL)
00757 return ((Header()->M1) == (1<<23));
00758 return false;
00759 }
00760
00761 bool AlEvent::VDETstatus()const
00762 {
00763 int runnum;
00764 if ((qhac->EH) != (EVEH*) NULL)
00765 runnum = qhac->EH->RN;
00766 else return false;
00767 if (runnum < 2001) return true;
00768
00769 bool badperiod = false;
00770 if (NoHVbit()->size() != 0)
00771 {
00772 for (vector<VHPV*>::iterator iter = NoHVbit()->begin(); iter < NoHVbit()->end();iter++)
00773 if ((runnum >= (*iter)->FR) && (runnum <= (*iter)->LR)) badperiod = true;
00774 }
00775 else return false;
00776 if (badperiod == false) return true;
00777
00778 int bit;
00779 if (VDETbit()->size() != 0)
00780 {
00781 for (vector<VHBV*>::iterator iter = VDETbit()->begin(); iter < VDETbit()->end();iter++)
00782 if ((runnum >= (*iter)->FR) && (runnum <= (*iter)->LR)) bit = (*iter)->BN;
00783 }
00784 else return false;
00785
00786 if (Readout()->size()>1)
00787 { if ((*Readout())[1] != NULL) return (((*Readout())[1]->CO[2])>>bit)&1;
00788 else if (TriggerLevelControl() != NULL) return ((TriggerLevelControl()->TR[0])>>bit)&1;
00789 else if (ReconstructorHeader() != NULL) return ((ReconstructorHeader()->DS)>>bit)&1;
00790 else if (LuminosityParameters() != NULL) return ((LuminosityParameters()->HV)>>bit)&1;
00791 else if (SicalLuminosityParameters() != NULL) return ((SicalLuminosityParameters()->HV)>>bit)&1;
00792 else return false;
00793 }
00794 else if (TriggerLevelControl() != NULL) return ((TriggerLevelControl()->TR[0])>>bit)&1;
00795 else if (ReconstructorHeader() != NULL) return ((ReconstructorHeader()->DS)>>bit)&1;
00796 else if (LuminosityParameters() != NULL) return ((LuminosityParameters()->HV)>>bit)&1;
00797 else if (SicalLuminosityParameters() != NULL) return ((SicalLuminosityParameters()->HV)>>bit)&1;
00798 else return false;
00799 }
00800
00801
00802
00803 void AlEvent::RedoTrigger()const
00804 {
00805 if(Readout()->size() == 0) return;
00806 if(Triggerlevel1Threshold()->size() == 0) return;
00807 if(Triggerlevel1Input()->size() == 0) return;
00808 int IHWSUM[72];
00809 int IEWSUM[72];
00810 int ILWSUM[8];
00811 int IECWTE[8];
00812 int IITSUM[4];
00813 for(vector<X1IP*>::iterator iter=Triggerlevel1Input()->begin();iter<Triggerlevel1Input()->end();iter++)
00814 {
00815 char name[5];
00816 strncpy(name,(*iter)->IT,4);
00817 name[4] = '\0';
00818 if ((strcasecmp(name, "HCW ") == 0 ))
00819 for(int j=0;j<72;j+=2)
00820 {
00821 IHWSUM[j] = (((*iter)->CO[j])/65536);
00822 IHWSUM[j+1] = (((*iter)->CO[j])%65536);
00823 }
00824 else if((strcasecmp(name, "ECW ") == 0 ))
00825 for(int j=0;j<72;j+=2)
00826 {
00827 IEWSUM[j] = ((((*iter)->CO[j])/65536)-200);
00828 IEWSUM[j+1] = ((((*iter)->CO[j])%65536)-200);
00829 }
00830 else if((strcasecmp(name, "MISC") == 0 ))
00831 {
00832 for(int j=0;j<8;j++) ILWSUM[j] = (*iter)->CO[j];
00833 for(int j=0;j<8;j++) IECWTE[j] = (*iter)->CO[j];
00834 for(int j=0;j<4;j++) IITSUM[j] = (*iter)->CO[j];
00835 }
00836 }
00837 SimulateTrigger(IHWSUM,IEWSUM,ILWSUM,IECWTE,IITSUM);
00838 }
00839
00840 void AlEvent::RedoOldTrigger()const
00841 {
00842 if(TriggerOldlevel1Threshold()->size() == 0) return;
00843 int IHTSUM[72];
00844 int IHWSUM[72];
00845 int IETSUM[72];
00846 int IEWSUM[72];
00847 int ILTSUM[24];
00848 int IITSUM[4] = {0};
00849 int IECTTE[4] = {0};
00850 int IHCTTE[4] = {0};
00851 int IECWTE[8] = {0};
00852 if((TriggerLevelEventBitPattern() == NULL)||(Triggerlevel1Adc()->size() == 0)) return;
00853
00854 for(vector<X1AD*>::iterator iter=Triggerlevel1Adc()->begin();iter<Triggerlevel1Adc()->end();iter++)
00855 {
00856 char name[5];
00857 strncpy(name,(*iter)->IT,4);
00858 name[4] = '\0';
00859
00860 if ((strcasecmp(name, "HCT ") == 0 ))
00861 {
00862 for(int i=0;i<72;i+=2)
00863 {
00864 IHTSUM[i] = (5*((((*iter)->AV[i/2])/65536)-96));
00865 IHTSUM[i+1] = (5*((((*iter)->AV[i/2])%65536)-96));
00866 }
00867 }
00868
00869 else if ((strcasecmp(name, "HCW ") == 0 ))
00870 {
00871 for(int i=0;i<72;i+=2)
00872 {
00873 IHWSUM[i] = (((((*iter)->AV[i/2])/65536)-96)/150);
00874 IHWSUM[i+1] = (((((*iter)->AV[i/2])%65536)-96)/150);
00875 }
00876 }
00877
00878 else if ((strcasecmp(name, "ECT ") == 0 ))
00879 {
00880 for(int i=0;i<72;i+=2)
00881 {
00882 IETSUM[i] = (5*((((*iter)->AV[i/2])/65536)-96));
00883 IETSUM[i+1] = (5*((((*iter)->AV[i/2])%65536)-96));
00884 }
00885 }
00886
00887 else if ((strcasecmp(name, "ECW ") == 0 ))
00888 {
00889 for(int i=0;i<72;i+=2)
00890 {
00891 IEWSUM[i] = (10*((((*iter)->AV[i/2])/65536)-96));
00892 IEWSUM[i+1] = (10*((((*iter)->AV[i/2])%65536)-96));
00893 }
00894 }
00895
00896 else if ((strcasecmp(name, "LCT ") == 0 ))
00897 {
00898 for(int i=0;i<24;i+=2)
00899 {
00900 ILTSUM[i] = (40*((((*iter)->AV[i/2])/65536)-96));
00901 ILTSUM[i+1] = (40*((((*iter)->AV[i/2])%65536)-96));
00902 }
00903 }
00904 }
00905
00906 int KST;
00907
00908 for (int i=0;i<72;i++)
00909 {
00910 if (i<12) KST = 0;
00911 else if (i>=60) KST = 1;
00912 else KST = 2;
00913 IHCTTE[KST] += IHTSUM[i];
00914 }
00915 IHCTTE[3] = (IHCTTE[0] + IHCTTE[1] + IHCTTE[2]);
00916
00917 for (int i=0;i<72;i++)
00918 {
00919 if (i<12) KST = 0;
00920 else if (i>=60) KST = 1;
00921 else KST = 2;
00922 IECTTE[KST] += IETSUM[i];
00923 }
00924 IECTTE[3] = (IECTTE[0] + IECTTE[1] + IECTTE[2]);
00925
00926 for (int i=0;i<72;i+=2)
00927 {
00928 if (i<24) KST = 0;
00929 else if (i>=48) KST = 1;
00930 else KST = 2;
00931 IECWTE[KST] += IEWSUM[i];
00932 IECWTE[KST+4] += IEWSUM[i+1];
00933 }
00934 IECWTE[3] = (IECWTE[0] + IECWTE[1] + IECWTE[2]);
00935 IECWTE[7] = (IECWTE[4] + IECWTE[5] + IECWTE[6]);
00936
00937 if(TriggerLevelEventBitPattern() != NULL)
00938 for(int i=0;i<4;i++) IITSUM[i] = TriggerLevelEventBitPattern()->IT[i];
00939
00940 if (TriggerLevelEventBitPattern() == NULL) qhac->EB = new XTEB;
00941 TriggerLevelEventBitPattern()->T1 = 0;
00942 TriggerLevelEventBitPattern()->T2 = 0;
00943 TriggerLevelEventBitPattern()->L2 = 0;
00944 for (int i=0;i<12;i++)
00945 {
00946 TriggerLevelEventBitPattern()->HT[i] = 0;
00947 TriggerLevelEventBitPattern()->HW[i] = 0;
00948 TriggerLevelEventBitPattern()->LW[i] = 0;
00949 TriggerLevelEventBitPattern()->EW[i] = 0;
00950 TriggerLevelEventBitPattern()->LT[i/3] = 0;
00951 TriggerLevelEventBitPattern()->TE[i/6] = 0;
00952 TriggerLevelEventBitPattern()->IT[i/3] = 0;
00953 TriggerLevelEventBitPattern()->TP[i/3] = 0;
00954 }
00955
00956 SimulateOldTrigger(IHTSUM, IHWSUM, IETSUM, IEWSUM, ILTSUM, IITSUM, IECTTE, IHCTTE, IECWTE);
00957
00958 }
00959
00960 void AlEvent::SimulateTrigger(int* IHWSUM, int* IEWSUM, int* ILWSUM, int* IECWTE, int* IITSUM)const
00961 {
00962 int NHWBIT[8] = {0};
00963 int NEWBIT[8] = {0};
00964 int NITBIT[8] = {0};
00965 int NLWBIT = 0;
00966 int NTEBIT = 0;
00967 X1TV *HCWI,*ECEC,*ECBA,*ETEC,*ETBA,*LCEC;
00968
00969 for(vector<X1TV*>::iterator iter=Triggerlevel1Threshold()->begin();iter<Triggerlevel1Threshold()->end();iter++)
00970 {
00971 char name[5];
00972 strncpy(name,(*iter)->TT,4);
00973 name[4] = '\0';
00974 if ((strcasecmp(name, "HCWI") == 0 )) HCWI = (*iter);
00975 if ((strcasecmp(name, "ECEC") == 0 )) ECEC = (*iter);
00976 if ((strcasecmp(name, "ECBA") == 0 )) ECBA = (*iter);
00977 if ((strcasecmp(name, "ETEC") == 0 )) ETEC = (*iter);
00978 if ((strcasecmp(name, "ETBA") == 0 )) ETBA = (*iter);
00979 if ((strcasecmp(name, "LCEC") == 0 )) LCEC = (*iter);
00980 }
00981
00982 for(int i=1;i<=4;i++)
00983 {
00984 int ibit=1;
00985 for(int j=1;j<=72;j++)
00986 {
00987 int jbit,k;
00988 if (ibit>32)
00989 {
00990 jbit = ibit - 32 - 1;
00991 k = 2*i-1;
00992 }
00993 else
00994 {
00995 jbit = ibit - 1;
00996 k = 2*i;
00997 }
00998 if (IHWSUM[j-1] >= HCWI->TV[i-1]) NHWBIT[k-1] |= (1<<jbit);
00999 ibit++;
01000 if(j == 36) ibit = 25;
01001 }
01002 }
01003
01004 for(int i=1;i<=4;i++)
01005 {
01006 float KECEC = (ECEC->TV[i-1]/2.);
01007 float KECBA = (ECBA->TV[i-2]/2.);
01008 for(int j=1;j<=72;j+=2)
01009 {
01010 if(j<24)
01011 {
01012
01013 if((IEWSUM[j-1] <= KECEC) || (IEWSUM[j] <= KECEC)) continue;
01014 int jbit = ((j+3)/4 - 1);
01015 NEWBIT[2*i-1] |= (1<<jbit);
01016 NEWBIT[2*i-1] |= (1<<(jbit+6));
01017 jbit = ((j+23)/2);
01018 NEWBIT[2*i-1] |= (1<<jbit);
01019 if(jbit == 23) jbit = 11;
01020 NEWBIT[2*i-1] |= (1<<(jbit+1));
01021 }
01022 else if(j>48)
01023 {
01024
01025 if((IEWSUM[j-1] <= KECEC) || (IEWSUM[j] <= KECEC)) continue;
01026 int jbit = ((j+15)/4);
01027 NEWBIT[2*i-2] |= (1<<jbit);
01028 NEWBIT[2*i-2] |= (1<<(jbit+6));
01029 jbit = ((j-41)/2);
01030 NEWBIT[2*i-2] |= (1<<jbit);
01031 if(jbit == 15) jbit = 3;
01032 NEWBIT[2*i-2] |= (1<<(jbit+1));
01033 }
01034 else
01035 {
01036
01037 if((IEWSUM[j-1] <= KECBA) || (IEWSUM[j] <= KECBA)) continue;
01038 int jbit = (j/2);
01039 NEWBIT[2*i-1] |= (1<<jbit);
01040 NEWBIT[2*i-2] |= (1<<(jbit-8));
01041 if(jbit<20) NEWBIT[2*i-1] |= (1<<(jbit+12));
01042 else NEWBIT[2*i-2] |= (1<<(jbit-20));
01043 }
01044 }
01045 }
01046
01047 int LW_A = ( ILWSUM[0] + ILWSUM[1] + ILWSUM[2] + ILWSUM[3] );
01048 int LW_B = ( ILWSUM[5] + ILWSUM[6] + ILWSUM[7] + ILWSUM[8] );
01049 for(int i=0;i<4;i++)
01050 {
01051 if(i<3)
01052 {
01053 if (LW_A > LCEC->TV[i]) NLWBIT |= (1<<i);
01054 if (LW_B > LCEC->TV[i]) NLWBIT |= (1<<(i+4));
01055 }
01056 else
01057 if ((LW_A+LW_B) > LCEC->TV[i]) NLWBIT |= (1<<i);
01058 }
01059
01060 SimulateSicalTrigger();
01061
01062 int ibit = 1;
01063 for(int j=1;j<=72;j++)
01064 {
01065 int jbit,k,kk,kb;
01066 if(ibit > 32)
01067 {
01068 jbit = ibit - 32 - 1;
01069 k=0;
01070 }
01071 else
01072 {
01073 jbit = ibit - 1;
01074 k=1;
01075 }
01076 if(j<=32)
01077 {
01078 kk=0;
01079 kb=j-1;
01080 }
01081 else if(j>64)
01082 {
01083 kk=2;
01084 kb=j - 64 - 1;
01085 }
01086 else
01087 {
01088 kk=1;
01089 kb=j - 32 - 1;
01090 }
01091 if(((IITSUM[kk]>>kb)&1)) NITBIT[k] |= (1<<jbit);
01092 ibit++;
01093 if(j == 36) ibit = 25;
01094 }
01095
01096 for(int i=0;i<4;i++)
01097 {
01098 float KETEC = (ETEC->TV[i]/2.);
01099 float KETBA = (ETBA->TV[i]/2.);
01100 if((IECWTE[0]>=KETEC) && (IECWTE[4]>=KETEC)) NTEBIT |= (1<<(4*i));
01101 if((IECWTE[1]>=KETEC) && (IECWTE[5]>=KETEC)) NTEBIT |= (1<<(4*i+1));
01102 if((IECWTE[2]>=KETBA) && (IECWTE[6]>=KETBA)) NTEBIT |= (1<<(4*i+2));
01103 }
01104
01105 ApplyTrigger(NHWBIT, NEWBIT, NITBIT, NLWBIT, NTEBIT);
01106 }
01107
01108
01109 void AlEvent::SimulateSicalTrigger()const
01110 {
01111
01112 float SIFOXA = 0.228;
01113 float SIDIFO = 0.00913;
01114 int Threshold[4]={9,12,22,41,};
01115 int Discri[2]={0};
01116 if (SicalRunConditions()->size() != 0)
01117 for(vector<SRCO*>::iterator iter=SicalRunConditions()->begin();iter<SicalRunConditions()->end();iter++)
01118 {
01119 char name[5];
01120 strncpy(name,(*iter)->NA,4);
01121 name[4] = '\0';
01122 if ((strcasecmp(name, "SIXA") == 0 )) SIFOXA = ((*iter)->VA *.001);
01123 if ((strcasecmp(name, "SIFO") == 0 )) SIDIFO = ((*iter)->VA *.00001);
01124 }
01125 if (SicalTriggerConditions() != NULL)
01126 {
01127 for(int i=0;i<4;i++) Threshold[i]=(255 & (SicalTriggerConditions()->TT>>(8*i)));
01128 Discri[0] = SicalTriggerConditions()->DO;
01129 Discri[1] = SicalTriggerConditions()->DE;
01130 }
01131
01132
01133 int ThermometerCode[2][2]={{0,0},{0,0}};
01134 for(int endcap=0;endcap<2;endcap++)
01135 for(int parity=0;parity<2;parity++)
01136
01137
01138
01139
01140 if(SicalTriggerSectorsAdc()->size() != 0)
01141 for(int road=0;road<2;road++)
01142 for(int sector=0;sector<8;sector++)
01143 {
01144 int IBT = 16*road + 8*endcap + sector;
01145 if (!((Discri[parity]>>IBT)&1))
01146 {
01147 int IADC =
01148 (((parity?
01149 (*SicalTriggerSectorsAdc())[endcap*8+sector]->AE:
01150 (*SicalTriggerSectorsAdc())[endcap*8+sector]->AO )>>(16*road))&65535);
01151 for(int i=0;i<4;i++)
01152 if(IADC > Threshold[i]) ThermometerCode[endcap][parity] |= (1<<i);
01153 }
01154 }
01155
01156 if (SicalTriggerX2() == NULL) qhac->X2 = new SIX2;
01157 SicalTriggerX2()->TW = 0;
01158
01159 int endcapA = (ThermometerCode[0][0] | ThermometerCode[0][1]);
01160 int endcapB = (ThermometerCode[1][0] | ThermometerCode[1][1]);
01161 if((endcapA&4)&&(endcapB&2)) SicalTriggerX2()->TW |= 1;
01162 if((endcapA&2)&&(endcapB&4)) SicalTriggerX2()->TW |= 2;
01163 if (endcapA&8) SicalTriggerX2()->TW |= 4;
01164 if (endcapB&8) SicalTriggerX2()->TW |= 8;
01165 if (endcapA&1) SicalTriggerX2()->TW |=16;
01166 if (endcapB&1) SicalTriggerX2()->TW |=32;
01167
01168 SicalTriggerX2()->TW |= ((ThermometerCode[0][0]&31)<<6);
01169 SicalTriggerX2()->TW |= ((ThermometerCode[0][1]&31)<<10);
01170 SicalTriggerX2()->TW |= ((ThermometerCode[1][0]&31)<<14);
01171 SicalTriggerX2()->TW |= ((ThermometerCode[1][1]&31)<<18);
01172 }
01173
01174
01175 void AlEvent::ApplyTrigger(int* NHWBIT, int* NEWBIT, int* NITBIT, int NLWBIT, int NTEBIT)const
01176 {
01177
01178 int NPHYTR[9] = {0};
01179
01180 int NTRBIT = 0;
01181 int ITRG11 = ( NITBIT[1] & NHWBIT[5] );
01182 int ITRG12 = ( NITBIT[0] & NHWBIT[4] );
01183 int ITRI1 = ( ITRG11 | ITRG12 );
01184 if (ITRI1) { NTRBIT |= (1<<8); NPHYTR[0]++;}
01185
01186 int ITRG21 = ( NITBIT[1] & NEWBIT[1] );
01187 int ITRG22 = ( NITBIT[0] & NEWBIT[0] );
01188 int ITRI2 = ( ITRG21 | ITRG22 );
01189 if (ITRI2) { NTRBIT |= (1<<9); NPHYTR[1]++;}
01190
01191 int ITRG31 = NEWBIT[5] ;
01192 int ITRG32 = NEWBIT[4] ;
01193 int ITRI3 = ( ITRG31 | ITRG32 );
01194 if (ITRI3) { NTRBIT |= (1<<2); NPHYTR[2]++;}
01195
01196 int ITRG42 = 0;
01197 int ITRG41 = 0;
01198 if (((NTEBIT>>2)&1)) ITRG41 |= 1;
01199 if (ITRG41) { NTRBIT |= (1<<17); NPHYTR[3]++;}
01200
01201 int ITRG52 = 0;
01202 int ITRG51 = 0;
01203 if (((NTEBIT>>4)&1)) ITRG51 |= 1;
01204 if (ITRG51) { NTRBIT |= (1<<18); NPHYTR[4]++;}
01205
01206 int ITRG62 = 0;
01207 int ITRG61 = 0;
01208 if (((NTEBIT>>5)&1)) ITRG61 |= 1;
01209 if (ITRG61) { NTRBIT |= (1<<19); NPHYTR[5]++;}
01210
01211 int ITRG72 = 0;
01212 int ITRG71 = 0;
01213 if ( ((NTEBIT>>0)&1) && ((NTEBIT>>1)&1) ) ITRG71 |= 1;
01214 if (ITRG71) { NTRBIT |= (1<<20); NPHYTR[6]++;}
01215
01216 int ITRG82 = 0;
01217 int ITRG81 = 0;
01218 if ( ((NLWBIT>>1)&1) && ((NLWBIT>>5)&1) && ((NLWBIT>>3)&1) ) ITRG81 |= 1;
01219 if (ITRG81) { NTRBIT |= (1<<7); NPHYTR[7]++;}
01220
01221 int ITRG92 = 0;
01222 int ITRG91 = 0;
01223 int MT2 = 0;
01224 int ITWORD = 0;
01225 if(SicalTriggerX2() != NULL)
01226 {
01227 ITWORD = SicalTriggerX2()->TW;
01228 if (ITWORD != 0)
01229 {
01230
01231 if ( ((ITWORD>>5)&1) || ((ITWORD>>4)&1) ) MT2 |= 1;
01232
01233 if ( ((ITWORD>>0)&1) || ((ITWORD>>1)&1) ) MT2 |= 2;
01234
01235 if ( ((ITWORD>>2)&1) || ((ITWORD>>3)&1) ) MT2 |= 4;
01236 }
01237 }
01238 ITRG91 = ITWORD;
01239 if (MT2) { NTRBIT |= (1<<4); NPHYTR[8]++;}
01240
01241
01242 bool exist = false;
01243 for(vector<X1RG*>::iterator iter=Readout()->begin();iter<Readout()->end();iter++)
01244 {
01245 char tmp[5];
01246 strncpy(tmp,(*iter)->NA,4);
01247 tmp[4] = '\0';
01248 if ((strcasecmp(tmp, "TPR ") == 0 ))
01249 {
01250
01251 ((*iter)->CO[0]) = NTRBIT;
01252 ((*iter)->CO[1]) = NTRBIT;
01253 ((*iter)->CO[2]) = NTRBIT;
01254 exist = true;
01255 }
01256 }
01257
01258 if (!exist)
01259 {
01260 vector<X1RG*>::iterator pos=Readout()->begin();
01261 pos++;
01262 X1RG* RowToAdd = new X1RG;
01263 Readout()->insert(pos,RowToAdd);
01264 pos=Readout()->begin();
01265 pos++;
01266 ((*pos)->CO[0]) = NTRBIT;
01267 ((*pos)->CO[1]) = NTRBIT;
01268 ((*pos)->CO[2]) = NTRBIT;
01269 }
01270 }
01271
01272 void AlEvent::SimulateOldTrigger(int* IHTSUM, int* IHWSUM, int* IETSUM, int* IEWSUM, int* ILTSUM, int* IITSUM, int* IECTTE, int* IHCTTE, int* IECWTE)const
01273 {
01274 int NHTBIT[8] = {0};
01275 int NHWBIT[8] = {0};
01276 int NETBIT[8] = {0};
01277 int NEWBIT[8] = {0};
01278 int NLTBIT[8] = {0};
01279 int NITBIT[8] = {0};
01280 int NTEBIT = 0;
01281 X1TH *ECTR,*ECWI,*HCTR,*HCWI,*LCTR,*ECTT,*ECTW,*HCTT;
01282
01283 for(vector<X1TH*>::iterator iter=TriggerOldlevel1Threshold()->begin();iter<TriggerOldlevel1Threshold()->end();iter++)
01284 {
01285 char name[5];
01286 strncpy(name,(*iter)->TT,4);
01287 name[4] = '\0';
01288 if ((strcasecmp(name, "ECTR") == 0 )) ECTR = (*iter);
01289 if ((strcasecmp(name, "ECWI") == 0 )) ECWI = (*iter);
01290 if ((strcasecmp(name, "HCTR") == 0 )) HCTR = (*iter);
01291 if ((strcasecmp(name, "HCWI") == 0 )) HCWI = (*iter);
01292 if ((strcasecmp(name, "LCTR") == 0 )) LCTR = (*iter);
01293 if ((strcasecmp(name, "ECTT") == 0 )) ECTT = (*iter);
01294 if ((strcasecmp(name, "ECTW") == 0 )) ECTW = (*iter);
01295 if ((strcasecmp(name, "HCTT") == 0 )) HCTT = (*iter);
01296 }
01297
01298 int KK=-1;
01299 for(int i=1;i<=4;i++)
01300 {
01301 int ibit=1;
01302 for(int j=1;j<=72;j++)
01303 {
01304 int jbit,kbit,k;
01305 if (ibit>32)
01306 {
01307 jbit = ibit - 32 - 1;
01308 k = 2*i-1;
01309 }
01310 else
01311 {
01312 jbit = ibit - 1;
01313 k = 2*i;
01314 }
01315 kbit = ((j-1)%32);
01316 if (!kbit) KK++;
01317 if ((IHTSUM[j-1] > HCTR->TV[i-1])||(HCTR->TV[i-1] == 0))
01318 {
01319 NHTBIT[k-1] |= (1<<jbit);
01320 TriggerLevelEventBitPattern()->HT[KK] |= (1<<kbit);
01321 }
01322 if (IHWSUM[j-1] >= HCWI->TV[i-1])
01323 {
01324 NHWBIT[k-1] |= (1<<jbit);
01325 TriggerLevelEventBitPattern()->HW[KK] |= (1<<kbit);
01326 }
01327 if ((IETSUM[j-1] > ECTR->TV[i-1])||(ECTR->TV[i-1] == 0))
01328 {
01329 NETBIT[k-1] |= (1<<jbit);
01330 TriggerLevelEventBitPattern()->LW[KK] |= (1<<kbit);
01331 }
01332 if (IEWSUM[j-1] >= ECWI->TV[i-1])
01333 TriggerLevelEventBitPattern()->EW[KK] |= (1<<kbit);
01334 ibit++;
01335 if(j == 36) ibit = 25;
01336 }
01337 }
01338
01339 for(int i=1;i<=4;i++)
01340 {
01341 for(int j=1;j<=72;j+=2)
01342 {
01343 if((IEWSUM[j-1] <= ECWI->TV[i-1]) || (IEWSUM[j] <= ECWI->TV[i-1])) continue;
01344 if(j<24)
01345 {
01346
01347 int jbit = ((j+3)/4 - 1);
01348 NEWBIT[2*i-1] |= (1<<jbit);
01349 NEWBIT[2*i-1] |= (1<<(jbit+6));
01350 jbit = ((j+23)/2);
01351 NEWBIT[2*i-1] |= (1<<jbit);
01352 if(jbit == 23) jbit = 11;
01353 NEWBIT[2*i-1] |= (1<<(jbit+1));
01354 }
01355 else if(j>48)
01356 {
01357
01358 int jbit = ((j+15)/4);
01359 NEWBIT[2*i-2] |= (1<<jbit);
01360 NEWBIT[2*i-2] |= (1<<(jbit+6));
01361 jbit = ((j-41)/2);
01362 NEWBIT[2*i-2] |= (1<<jbit);
01363 if(jbit == 15) jbit = 3;
01364 NEWBIT[2*i-2] |= (1<<(jbit+1));
01365 }
01366 else
01367 {
01368
01369 int jbit = (j/2);
01370 NEWBIT[2*i-1] |= (1<<jbit);
01371 NEWBIT[2*i-2] |= (1<<(jbit-8));
01372 if(jbit<20) NEWBIT[2*i-1] |= (1<<(jbit+12));
01373 else NEWBIT[2*i-2] |= (1<<(jbit-20));
01374 }
01375 }
01376 }
01377
01378 for(int i=0;i<4;i++)
01379 {
01380 for(int j=0;j<24;j++)
01381 {
01382 if(ILTSUM[j] > LCTR->TV[i]) NLTBIT[i] |= (1<<j);
01383 if((j>12)&&(ILTSUM[j]>LCTR->TV[i])) NLTBIT[i+4] |= (1<<((j+6)%12));
01384 }
01385 TriggerLevelEventBitPattern()->LT[i] = NLTBIT[i];
01386 }
01387
01388 SimulateSicalTrigger();
01389
01390 int ibit = 1;
01391 for(int j=1;j<=72;j++)
01392 {
01393 int jbit,k,kk,kb;
01394 if(ibit > 32)
01395 {
01396 jbit = ibit - 32 - 1;
01397 k=0;
01398 }
01399 else
01400 {
01401 jbit = ibit - 1;
01402 k=1;
01403 }
01404 if(j<=32)
01405 {
01406 kk=0;
01407 kb=j-1;
01408 }
01409 else if(j>64)
01410 {
01411 kk=2;
01412 kb=j - 64 - 1;
01413 }
01414 else
01415 {
01416 kk=1;
01417 kb=j - 32 - 1;
01418 }
01419 if(((IITSUM[kk]>>kb)&1)) NITBIT[k] |= (1<<jbit);
01420 ibit++;
01421 if(j == 36) ibit = 25;
01422 }
01423 TriggerLevelEventBitPattern()->IT[0] = NITBIT[1];
01424 TriggerLevelEventBitPattern()->IT[1] = ((((NITBIT[0]>>0)&15)<<0)|(((NITBIT[0]>>4)&65535)<<4));
01425 TriggerLevelEventBitPattern()->IT[2] = IITSUM[2];
01426 TriggerLevelEventBitPattern()->IT[3] = IITSUM[3];
01427
01428 int KECTW[4]={2300,2300,2800,3500};
01429 for(int i=0;i<4;i++)
01430 {
01431 if(IHCTTE[i]>HCTT->TV[i]) NTEBIT |= (1<<i);
01432 if(IECTTE[i]>ECTT->TV[i]) NTEBIT |= (1<<(i+4));
01433 if(IECWTE[i]>ECTW->TV[i]) NTEBIT |= (1<<(i+8));
01434 if(IECWTE[i+4]>ECTW->TV[i]) NTEBIT |= (1<<(i+12));
01435 if(IECWTE[i]>KECTW[i]) NTEBIT |= (1<<(i+24));
01436 if(IECWTE[i+4]>KECTW[i]) NTEBIT |= (1<<(i+28));
01437 }
01438 TriggerLevelEventBitPattern()->TE[0] = ((((NTEBIT>>0)&15)<<0)|(((NTEBIT>>4)&15)<<16));
01439 TriggerLevelEventBitPattern()->TE[1] = ((((NTEBIT>>8)&15)<<0)|(((NTEBIT>>24)&15)<<4)
01440 |(((NTEBIT>>12)&15)<<16)|(((NTEBIT>>28)&15)<<20));
01441
01442
01443 ApplyOldTrigger(NHTBIT, NHWBIT, NETBIT, NEWBIT, NLTBIT, NITBIT, NTEBIT);
01444
01445
01446
01447
01448 for(vector<X1AD*>::iterator iter=Triggerlevel1Adc()->begin();iter<Triggerlevel1Adc()->end();iter++)
01449 delete (*iter);
01450 Triggerlevel1Adc()->resize(5);
01451 for(vector<X1AD*>::iterator iter=Triggerlevel1Adc()->begin();iter<Triggerlevel1Adc()->end();iter++)
01452 (*iter) = new X1AD;
01453
01454 vector<X1AD*>::iterator x1ad = Triggerlevel1Adc()->begin();
01455 strncpy((*x1ad)->IT,"HCT ",4);
01456 for(int i=0;i<72;i+=2)
01457 (*x1ad)->AV[i/2] = (((((IHTSUM[i]/5)+96)<4096)?((IHTSUM[i]/5)+96):4096)*65536
01458 + (((IHTSUM[i+1]/5)+96)<4096?((IHTSUM[i+1]/5)+96):4096));
01459 x1ad++;
01460 strncpy((*x1ad)->IT,"HCW ",4);
01461 for(int i=0;i<72;i+=2)
01462 (*x1ad)->AV[i/2] = (((((IHWSUM[i]*150)+96)<4096)?((IHWSUM[i]*150)+96):4096)*65536
01463 + (((IHWSUM[i+1]*150)+96)<4096?((IHWSUM[i+1]*150)+96):4096));
01464 x1ad++;
01465 strncpy((*x1ad)->IT,"ECT ",4);
01466 for(int i=0;i<72;i+=2)
01467 {
01468 int num1 = ((((IETSUM[i]/5)+96)<4096)?((IETSUM[i]/5)+96):4096);
01469 int num2 = (((IETSUM[i+1]/5)+96)<4096?((IETSUM[i+1]/5)+96):4096);
01470 (*x1ad)->AV[i/2] = ((num1>0)?num1:0)*65536 + ((num2>0)?num2:0);
01471 }
01472 x1ad++;
01473 strncpy((*x1ad)->IT,"ECW ",4);
01474 for(int i=0;i<72;i+=2)
01475 (*x1ad)->AV[i/2] = (((((IEWSUM[i]/10)+96)<4096)?((IEWSUM[i]/10)+96):4096)*65536
01476 + (((IEWSUM[i+1]/10)+96)<4096?((IEWSUM[i+1]/10)+96):4096));
01477 x1ad++;
01478 strncpy((*x1ad)->IT,"LCT ",4);
01479 for(int i=0;i<24;i+=2)
01480 (*x1ad)->AV[i/2] = (((((ILTSUM[i]/40)+96)<4096)?((ILTSUM[i]/40)+96):4096)*65536
01481 + (((IEWSUM[i+1]/40)+96)<4096?((IEWSUM[i+1]/40)+96):4096));
01482
01483 }
01484
01485 void AlEvent::ApplyOldTrigger(int* NHTBIT, int* NHWBIT, int* NETBIT, int* NEWBIT, int* NLTBIT, int* NITBIT, int NTEBIT)const
01486 {
01487
01488 int NPHYTR[9] = {0};
01489
01490 int NTRBIT = 0;
01491 int ITRG11 = ( NITBIT[1] & NHWBIT[5] & NHTBIT[1]);
01492 int ITRG12 = ( NITBIT[0] & NHWBIT[4] & NHTBIT[0]);
01493 int ITRI1 = ( ITRG11 | ITRG12 );
01494 if (ITRI1) { NTRBIT |= (1<<0); NPHYTR[0]++;}
01495
01496 int ITRG21 = ( NITBIT[1] & NEWBIT[3] & NETBIT[5]);
01497 int ITRG22 = ( NITBIT[0] & NEWBIT[2] & NETBIT[4]);
01498 int ITRI2 = ( ITRG21 | ITRG22 );
01499 if (ITRI2) { NTRBIT |= (1<<1); NPHYTR[1]++;}
01500
01501 int ITRG31 = NEWBIT[7] & NETBIT[7];
01502 int ITRG32 = NEWBIT[6] & NETBIT[6] ;
01503 int ITRI3 = ( ITRG31 | ITRG32 );
01504 if (ITRI3) { NTRBIT |= (1<<2); NPHYTR[2]++;}
01505
01506
01507
01508
01509 int ITRG51 = (NITBIT[1] & NHWBIT[1] & NHTBIT[3]);
01510 int ITRG52 = (NITBIT[0] & NHWBIT[0] & NHTBIT[2]);
01511 int ITRI5 = ( ITRG51 | ITRG52 );
01512 if (ITRG51) { NTRBIT |= (1<<4); NPHYTR[4]++;}
01513
01514 int ITRG61 = ( NHWBIT[3] & NHTBIT[5]);
01515 int ITRG62 = ( NHWBIT[2] & NHTBIT[4]);
01516 int ITRI6 = ( ITRG61 | ITRG62 );
01517 if (ITRG61) { NTRBIT |= (1<<5); NPHYTR[5]++;}
01518
01519 int ITRG71 = 0;
01520 int ITRG72 = 0;
01521 if (((NTEBIT>>10)&1)&&((NTEBIT>>14)&1)) ITRG71 |= (1<<17);
01522 if (((NTEBIT>>12)&1)&&((NTEBIT>>13)&1)
01523 &&((NTEBIT>>8)&1)&&((NTEBIT>>9)&1)) ITRG71 |= (1<<20);
01524 if (((NTEBIT>>24)&1)&&((NTEBIT>>28)&1)) ITRG71 |= (1<<24);
01525 if (((NTEBIT>>25)&1)&&((NTEBIT>>29)&1)) ITRG71 |= (1<<25);
01526 if (ITRG71) { NTRBIT |= (1<<6); NPHYTR[6]++;}
01527
01528 int ITRG81 = 0;
01529 int ITRG82 = 0;
01530 if (NLTBIT[1]) ITRG81 |= (1<<0);
01531 if ((NLTBIT[2]&4095)&&(NLTBIT[2]&16773120)) ITRG81 |= (1<<3);
01532 if (NLTBIT[2]&4095) ITRG81 |= (1<<4);
01533 if (NLTBIT[2]&16773120) ITRG81 |= (1<<5);
01534 if (NLTBIT[3]&4095) ITRG81 |= (1<<6);
01535 if (NLTBIT[3]&16773120) ITRG81 |= (1<<7);
01536 if ((NLTBIT[2]&4095)&&(NLTBIT[3]&16773120)) ITRG81 |= (1<<14);
01537 if ((NLTBIT[3]&4095)&&(NLTBIT[2]&16773120)) ITRG81 |= (1<<15);
01538 if (ITRG81) { NTRBIT |= (1<<7); NPHYTR[7]++;}
01539
01540 int ITRG92 = 0;
01541 int ITRG91 = 0;
01542 int MT2 = 0;
01543 int ITWORD = 0;
01544 if(SicalTriggerX2() != NULL)
01545 {
01546 ITWORD = SicalTriggerX2()->TW;
01547 if (ITWORD != 0)
01548 {
01549
01550 if ( ((ITWORD>>5)&1) || ((ITWORD>>4)&1) ) MT2 |= 1;
01551
01552 if ( ((ITWORD>>0)&1) || ((ITWORD>>1)&1) ) MT2 |= 2;
01553
01554 if ( ((ITWORD>>2)&1) || ((ITWORD>>3)&1) ) MT2 |= 4;
01555 }
01556 }
01557 ITRG91 = ITWORD;
01558 if (MT2) { NTRBIT |= (1<<8); NPHYTR[8]++;}
01559
01560 TriggerLevelEventBitPattern()->T1 = (ITRG71|ITRG81|
01561 (((NTRBIT>>2)&1)<<2)|
01562 (((NTRBIT>>0)&3)<<8)|
01563 (((NTRBIT>>4)&3)<<11));
01564 }
01565
01566 float AlEvent::getGeneratorWeight(int number) const {
01567
01568 if(GeneratorWeights()->size() == 0) return -1;
01569 for(vector<KWGT*>::iterator iter=GeneratorWeights()->begin();iter<GeneratorWeights()->end();iter++){
01570 if((*iter)->WN==number) {return (*iter)->WV;}
01571 }
01572 return -1;
01573 }