#ifdef __GNUG__ #pragma implementation #endif #include "Stntuple/obj/TStnTriggerTable.hh" #include "Stntuple/obj/TStnTriggerBlock.hh" #include "Stntuple/obj/TStnMcCalibrations.hh" #include #include #include "Stntuple/obj/TStnHeaderBlock.hh" #include "TMath.h" ClassImp(TStnTriggerBlock) //______________________________________________________________________________ void TStnTriggerBlock::ReadV1(TBuffer &R__b) { // Read in versions 1 of class TStnTriggerBlock. R__b.ReadFastArray(fTsid.Data(),kNwordsV1); } //______________________________________________________________________________ void TStnTriggerBlock::ReadV2(TBuffer &R__b) { // Read in versions 2 of class TStnTriggerBlock. R__b.ReadFastArray(fTsid.Data(),kNwordsV2); fTl3d.Streamer(R__b); } //______________________________________________________________________________ void TStnTriggerBlock::ReadV3(TBuffer &R__b) { // Read in versions 3 of class TStnTriggerBlock. R__b.ReadFastArray(fTsid.Data(),kNwordsV3); fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); } //______________________________________________________________________________ void TStnTriggerBlock::ReadV4(TBuffer &R__b) { // Read in versions 4,5 of class TStnTriggerBlock. At this point there was a // change resulting in removal of 1 word per class... (pointer to virtual // functions) // fL1Info ... fL3Info can't be restored... int buf [100]; R__b.ReadFastArray(buf,kNwordsV3); memcpy(fTsid.Data(),buf ,4*sizeof(int)); memcpy(fTfrd.Data(),buf+ 5,11*sizeof(int)); memcpy(fTl1d.Sumet (),buf+17,4*sizeof(int)); memcpy(fTl1d.Caltrg(),buf+22,4*sizeof(int)); memcpy(fTl1d.Mutrg (),buf+27,4*sizeof(int)); memcpy(fTl1d.Trktrg(),buf+32,4*sizeof(int)); memcpy(fTl1d.Bsctrg(),buf+37,4*sizeof(int)); memcpy(fTl1d.Multi (),buf+42,4*sizeof(int)); // whats left: 1 word... memcpy(fL1Info.Data(),buf+47,1*sizeof(int)); fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); fTcmd.Streamer(R__b); } //______________________________________________________________________________ void TStnTriggerBlock::ReadV5(TBuffer &R__b) { // Read in version 5 of class TStnTriggerBlock. At this point there was a // change resulting in removal of 1 word per class... (pointer to virtual // functions) R__b.ReadFastArray(fTsid.Data(),kNwordsV3); fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); fTcmd.Streamer(R__b); } //______________________________________________________________________________ void TStnTriggerBlock::ReadV6(TBuffer &R__b) { // Read in version 6 of class TStnTriggerBlock. // v6 still was writing 16 words for TL1d R__b.ReadFastArray(fTsid.Data(),kNwordsV3); R__b.ReadFastArray(Beam,4); fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); fTcmd.Streamer(R__b); } //______________________________________________________________________________ void TStnTriggerBlock::Streamer(TBuffer &R__b) { // Stream an object of class TStnTriggerBlock. Version_t version; if (R__b.IsReading()) { version = R__b.ReadVersion(); for(int i=0; i<4; i++) Beam[i] = 0.0; if (version == 1) ReadV1(R__b); else if (version == 2) ReadV2(R__b); else if (version == 3) ReadV3(R__b); else if (version == 4) ReadV4(R__b); else if (version == 5) ReadV5(R__b); else if (version == 6) ReadV6(R__b); else { // current version: 6 R__b.ReadFastArray(fTsid.Data(),kNwordsV6); R__b.ReadFastArray(Beam,4); // read TL2D, TL3D and TCMD fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); fTcmd.Streamer(R__b); } } else { R__b.WriteVersion(TStnTriggerBlock::IsA()); // write fixed part R__b.WriteFastArray(fTsid.Data(),kNwordsV6); R__b.WriteFastArray(Beam,4); // write TL2D, TL3D, TCMD fTl2d.Streamer(R__b); fTl3d.Streamer(R__b); fTcmd.Streamer(R__b); } } //_____________________________________________________________________________ TStnTriggerBlock::TStnTriggerBlock() { for(int i=0; i<4; i++) Beam[i] = 0.0; } //_____________________________________________________________________________ TStnTriggerBlock::~TStnTriggerBlock() { } //_____________________________________________________________________________ Int_t TStnTriggerBlock::GetListOfPassedTriggers(const TStnTriggerTable* Table, const char* Name, Int_t Level, TObjArray* List) { // assume that trigger table has been already initialized // if Name=0 include all passed triggers if (List == 0) return -1; List->Clear(); if (Level == 1) { //----------------------------------------------------------------------------- // L1 triggers - there are 64 bits //----------------------------------------------------------------------------- for (int i=0; i<64; i++) { if (fTfrd.PrescaledL1Bit(i)) { // bit is ON, check the name if (i < Table->NL1Triggers()) { const TStnTrigger* trig = Table->GetTrigger(1,i); if ((Name == 0) || (strstr(trig->GetName(),Name) != 0)) { List->Add((TObject*)trig); } } } } } else if (Level == 2) { //----------------------------------------------------------------------------- // L2 triggers : 128 -> 192 bits //----------------------------------------------------------------------------- TTl2dL2Decision* l2 = fTl2d.L2Decision(); int nl2bits = fTl2d.NL2TriggerBitWords()*32; for (int i=0; iPrescaledBit(i)) { // bit is ON, check the name if (i < Table->NL2Triggers()) { const TStnTrigger* trig = Table->GetTrigger(2,i); if ((Name == 0) || (strstr(trig->GetName(),Name) != 0)) { List->Add((TObject*)trig); } } } } } else if (Level == 3) { //----------------------------------------------------------------------------- // L3 triggers //----------------------------------------------------------------------------- Int_t npaths = fTl3d.NPaths(); for (int i=0; iNL3Triggers()) { const TStnTrigger* trig = Table->GetTrigger(3,i); if ((Name == 0) || (strstr(trig->GetName(),Name) != 0)) { List->Add((TObject*)trig); } } } } } else { Error("GetListOfTriggers","Level %i doesn't exist!\n"); } return List->GetEntriesFast(); } //_____________________________________________________________________________ void TStnTriggerBlock::Clear(Option_t* opt) { // Tsid, Tfrd and Tl1d are filled by memory copy, so they don't require // to be cleared fTl2d.Data()->Clear(); fTl3d.Clear(); fTcmd.Data()->Clear(); fL1Info.Clear(); fL2Info.Clear(); fL3Info.Clear(); } //_____________________________________________________________________________ void TStnTriggerBlock::Print(Option_t* opt) const { // print contents of the trigger block // TSID printf(" ---------------------------------- TSID ------------------------------\n"); printf(" part mess_id bc bheader turn_counter B0 BC TI AM Myron L2B ev_id \n"); printf(" ----------------------------------------------------------------------\n"); printf(" %4i",fTsid.PartitionNumber()); printf(" %7i",fTsid.MessageId()); printf(" %2i",fTsid.BunchCounter()); printf(" %6x",fTsid.BoardHeader()); printf(" %10i",fTsid.TurnCounter()); printf(" %2i",fTsid.B0Marker()); printf(" %2i",fTsid.BCMarker()); printf(" %2i",fTsid.TIMarker()); printf(" %2i",fTsid.AbortMarker()); printf(" %2i",fTsid.MyronBucket()); printf(" %1i",fTsid.L2Buffer()); printf(" %10i",fTsid.EventId()); printf("\n"); if (strstr(opt,"tl1d") != 0 || strstr(opt,"TL2D") != 0) { fTl1d.Print(); } if (strstr(opt,"tl2d") == 0 || strstr(opt,"TL2D") != 0) { fTl2d.Print(); } } //_____________________________________________________________________________ Int_t TStnTriggerBlock::GetEntry(Int_t TreeEntry){ int current_entry = fEvent->GetCurrentEntry(); if (fCurrentEntry == current_entry) return 1; fCurrentEntry = current_entry; int out= fNode->GetEntry(TreeEntry); TStnEvent* ev= GetEvent(); TStnHeaderBlock* headerblock= (TStnHeaderBlock*) ev->GetDataBlock ("HeaderBlock"); Int_t mcflag=headerblock->McFlag(); if (mcflag==0) return out; //---------------------------------------------------------------------- //2009-06-05 //Code to pacth the usage of wrong SCL constants in ADC->GEV coversions //in MC production. Correct Em and Had energy of L2 cluster based on //the seed position //---------------------------------------------------------------------- int rn=headerblock->RunNumber(); TStnMcCalibrations _fCALDIGITOGEV3_MC; _fCALDIGITOGEV3_MC.InitMC(rn); TStnMcCalibrations _fCALDIGITOGEV3; _fCALDIGITOGEV3.Init(rn); TTl2d* tl2d = Tl2d(); //----------------------------------------------------------------------------- // 2009-06-05 // format of the emulated TL2D doesn't allow to assign version correctly // based on the number of L2 trigger words... fix by hands // this code may break at a point when MC Production will start writing out // new TL2D format... hopefully not very soon... //----------------------------------------------------------------------------- if(rn<=186598 && tl2d->Version()==1) { int loc, n_l2_bit_words; tl2d->SetVersion(0); tl2d->SetL2ClusterSize(2); loc = tl2d->Data()->At(10); n_l2_bit_words = tl2d->NL2TriggerWords()-tl2d->Data()->At(loc); tl2d->SetNL2TriggerBitWords(n_l2_bit_words); } for (int i=0; iNL2Clusters(); i++) { TTl2dCluster* l2clu = tl2d->Cluster(i); int iw=l2clu->IEta(); Float_t Em = l2clu->EtEmGeV(); Float_t Had= l2clu->EtHadGeV(); if (Em==0 && Had==0) continue; double K1_h, K1_e, K2_h,K2_e; //Different sub-system for different eta => different scale for ADC to GeV conversion //-------------------- //Hadronic Calorimeter //-------------------- if ( (iw>=9 && iw<=11) || (iw>=12 && iw<=14) ){ K1_h = _fCALDIGITOGEV3_MC.GetChaScale(); K2_h = _fCALDIGITOGEV3.GetChaScale();} if ( iw==8 || iw==15 ){ //half had from WHA and half from CHA K1_h = (_fCALDIGITOGEV3_MC.GetChaScale()+_fCALDIGITOGEV3_MC.GetWhaScale())/2.; K2_h = (_fCALDIGITOGEV3. GetChaScale()+_fCALDIGITOGEV3. GetWhaScale())/2.;} if ( (iw>=6 && iw<=7 ) || (iw>=16 && iw<=17) ){ K1_h = _fCALDIGITOGEV3_MC.GetWhaScale(); K2_h = _fCALDIGITOGEV3. GetWhaScale();} if ( iw<6 || iw>17 ){ K1_h = _fCALDIGITOGEV3_MC.GetPhaScale(); K2_h = _fCALDIGITOGEV3. GetPhaScale();} //-------------------- //EM Calorimeter //-------------------- if ( (iw>=6 && iw<=11) || (iw>=12 && iw<=16) ){ K1_e = _fCALDIGITOGEV3_MC.GetCemScale(); K2_e = _fCALDIGITOGEV3. GetCemScale();} if ( iw<6 || iw>16){ K1_e = _fCALDIGITOGEV3_MC.GetPemScale(); K2_e = _fCALDIGITOGEV3. GetPemScale();} Em = Em * K1_e/K2_e; Had = Had * K1_h/K2_h; Int_t EmBit = (Int_t) ( (Em * 8.) + 0.5); Int_t HadBit = (Int_t) ( (Had * 8.)+ 0.5); EmBit = EmBit & 0xfff; HadBit = (HadBit << 16) & 0x0fff0000; //mask for the new Em and Had energy Int_t sum =(EmBit + HadBit) & 0x0fff0fff; Int_t word= l2clu->Word(0) & 0xf000f000; Int_t new_word=(word + sum); l2clu->SetWord(0,new_word); } return out; }