/////////////////////////////////////////////////////////////////////////////// // // Summary of fPrintLevel values: // ---------------------- // PrintLevel = 1: print Electron block for all the events // PrintLevel = 2: print run/event number for passed events // PrintLevel = 3: print run/event number for failed events // // PrintLevel = 39: // PrintLevel = 40: // PrintLevel = 101: print line per event with good electron // PrintLevel = 102: found matching non-trigger jet // PrintLevel = 103: event has a loose electron which fails delX(CES) cut // PrintLevel = 104: event has a loose electron which fails delZ(CES) cut // // PrintLevel = 201: print events failing trigger /////////////////////////////////////////////////////////////////////////////// #include "TF1.h" #include "TCanvas.h" #include "TPad.h" #include "TText.h" #include "TSystem.h" #include "Stntuple/obj/TStnHeaderBlock.hh" #include "Stntuple/obj/TStnTrackBlock.hh" #include "Stntuple/obj/TStnDBManager.hh" #include "Stntuple/alg/TStntuple.hh" #include "Stntuple/alg/TStnElectronID.hh" #include "Stntuple/obj/TStnTriggerTable.hh" #include "Stntuple/obj/TStnTrigger.hh" #include "Stntuple/loop/TStnAna.hh" #include "Stntuple/geom/TTrajectoryPoint.hh" #include "Stntuple/geom/TSimpleExtrapolator.hh" #include "TWenuMonModule.hh" ClassImp(TWenuMonModule) //_____________________________________________________________________________ TWenuMonModule::TWenuMonModule(const char* name, const char* title): TStnModule(name,title) { fListOfGoodElectrons = new TObjArray(20); fListOfLooseElectrons = new TObjArray(20); fTightID = new TStnElectronID(); fLooseID = new TStnElectronID(); fExtrapolator = new TSimpleExtrapolator(); //----------------------------------------------------------------------------- // cut values: //----------------------------------------------------------------------------- fMinNTightElectrons = 0; fMaxNTightElectrons = 100; fMinNLooseElectrons = 0; fMaxNLooseElectrons = 100; fMinNEmObjects = 0; fMaxNEmObjects = 100; //----------------------------------------------------------------------------- // modes: //----------------------------------------------------------------------------- fCutMode = 0; } //_____________________________________________________________________________ TWenuMonModule::~TWenuMonModule() { fListOfGoodElectrons->Clear(); delete fListOfGoodElectrons; fListOfLooseElectrons->Clear(); delete fListOfLooseElectrons; delete fTightID; delete fLooseID; delete fExtrapolator; } //_____________________________________________________________________________ int TWenuMonModule::BeginJob() { // register the data blocks and book histograms RegisterDataBlock("ElectronBlock", "TStnElectronBlock", &fElectronBlock); RegisterDataBlock("TriggerBlock" , "TStnTriggerBlock" , &fTriggerBlock); RegisterDataBlock("TrackBlock" , "TStnTrackBlock" , &fTrackBlock); RegisterDataBlock("MetBlock" , "TStnMetBlock" , &fMetBlock); BookHistograms(); //----------------------------------------------------------------------------- // handle print level //----------------------------------------------------------------------------- const char* env; env = gSystem->Getenv(Form("%s_PrintLevel",GetName())); if (env) { fPrintLevel = atoi(env); printf(" %s: fPrintLevel = %i\n",GetName(),fPrintLevel); } return 0; } //_____________________________________________________________________________ int TWenuMonModule::BeginRun() { int rn = GetHeaderBlock()->RunNumber(); TStntuple::Init(rn); TStntuple::InitListOfL3Triggers(this); return 0; } //_____________________________________________________________________________ void TWenuMonModule::FillEventHistograms(EventHist_t& Hist) { int nemo; Hist.fMet0 ->Fill(fMetBlock->Met(0)); Hist.fMet1 ->Fill(fMetBlock->Met(1)); Hist.fMet0VsMet1->Fill(fMetBlock->Met(1),fMetBlock->Met(0),1); Hist.fNTracks ->Fill(fTrackBlock->NTracks()); Hist.fNGoodEle->Fill(fNTightElectrons); Hist.fNLooseEle->Fill(fNLooseElectrons); //----------------------------------------------------------------------------- // transverse mass histograms //----------------------------------------------------------------------------- double metm[2], metx[2], mety[2], mt[2], q[2]; for (int i=0; i<2; i++) { metm[i] = fMetBlock->Met(i); metx[i] = metm[i]*cos(fMetBlock->MetPhi(i)); mety[i] = metm[i]*sin(fMetBlock->MetPhi(i)); } if (fNTightElectrons > 0) { nemo = fElectronBlock->NElectrons(); for (int i1=0; i1Electron(i1); const TLorentzVector* m1 = e1->Momentum(); if (fIdWord[i1] == 0) { mt[0] = sqrt(2*(e1->Et()*metm[0] -m1->Px()*metx[0]-m1->Py()*mety[0])); mt[1] = sqrt(2*(e1->Et()*metm[1] -m1->Px()*metx[1]-m1->Py()*mety[1])); Hist.fMt[0]->Fill(mt[0]); Hist.fMt[1]->Fill(mt[1]); //----------------------------------------------------------------------------- // distributions for isolation vs MET //----------------------------------------------------------------------------- Hist.fIsoVsMet->Fill(fMetBlock->Met(1),e1->Iso()); Hist.fIso1VsMet->Fill(fMetBlock->Met(1),e1->Iso()/e1->Et()); //----------------------------------------------------------------------------- // distributions for the component of MET perpendicular to the electron // momentum //----------------------------------------------------------------------------- q[0] = (metx[0]*m1->Py()-mety[0]*m1->Px())/m1->Pt(); q[1] = (metx[1]*m1->Py()-mety[1]*m1->Px())/m1->Pt(); Hist.fMetPerp[0]->Fill(q[0]); Hist.fMetPerp[1]->Fill(q[1]); } } } } //_____________________________________________________________________________ void TWenuMonModule::FillEEHistograms(EEHist_t& Hist, TStnElectron* E1 , TStnElectron* E2 ) { static TLorentzVector zmom; zmom = *E1->Momentum(); zmom += *E2->Momentum(); double charge = E1->Charge()+E2->Charge(); double mass = zmom.M(); double pt = zmom.Pt(); Hist.fMass->Fill(mass); Hist.fCharge->Fill(charge); Hist.fPt->Fill(pt); } //_____________________________________________________________________________ void TWenuMonModule::FillElectronHistograms(EleHist_t& Hist, TStnElectron* Ele) { const TLorentzVector* mom = Ele->Momentum(); Hist.fEt->Fill(Ele->Et()); Hist.fEtVsEta->Fill(mom->Eta(),Ele->Et()); Hist.fEOverP->Fill(Ele->EOverP()); if (Ele->Charge() > 0) { Hist.fWedgeVsDelXPos->Fill(Ele->DelX(),Ele->SeedIPhi()+24*Ele->Side()); Hist.fEOverPPos->Fill(Ele->EOverP()); } else { Hist.fWedgeVsDelXNeg->Fill(Ele->DelX(),Ele->SeedIPhi()+24*Ele->Side()); Hist.fEOverPNeg->Fill(Ele->EOverP()); } Hist.fWedgeVsZCes->Fill(Ele->ZCes(),Ele->WedgeNumber()); Hist.fWedgeVsDelZ->Fill(Ele->DelZ(),Ele->WedgeNumber()); Hist.fEmfrVsDelZ->Fill(Ele->DelZ(),Ele->Emfr(),1.); Hist.fPhi->Fill(TVector2::Phi_0_2pi(mom->Phi())); Hist.fIso->Fill(Ele->Iso()); Hist.fIso1->Fill(Ele->Iso()/Ele->Et()); Hist.fHadEm->Fill(Ele->HadEm()); Hist.fTrackPt->Fill(Ele->TrackPt()); Hist.fTrackXCes->Fill(Ele->TrackPt()); Hist.fTrackZCes->Fill(Ele->TrackPt()); Hist.fXCes->Fill(Ele->XCes()); Hist.fZCes->Fill(Ele->ZCes()); Hist.fLshr->Fill (Ele->Lshr()); Hist.fLshr2->Fill(Ele->Lshr2()); Hist.fDelX->Fill(Ele->DelX()); Hist.fDelZ->Fill(Ele->DelZ()); Hist.fNCesStripClusters->Fill(Ele->NCesClusters(0)); Hist.fNCesWireClusters->Fill(Ele->NCesClusters(1)); Hist.fCesStripEnergy->Fill(Ele->CesEnergy(0)); Hist.fCesWireEnergy->Fill(Ele->CesEnergy(1)); Hist.fCesStripChi2->Fill(Ele->Chi2Strip()); Hist.fCesWireChi2->Fill(Ele->Chi2Wire()); Hist.fCesEStripVsEWire->Fill(Ele->CesEnergy(1),Ele->CesEnergy(0),1); Hist.fCesEStripVsEta[0]->Fill(Ele->CesEnergy(1),mom->Eta(),1); Hist.fCesEStripVsEt [0]->Fill(Ele->CesEnergy(1),mom->E(),1); double estrip_corr = Ele->CesEnergy(1)*Ele->Et()/mom->E(); Hist.fCesEStripVsEta[1]->Fill(estrip_corr,mom->Eta(),1); Hist.fCesEStripVsEt [1]->Fill(estrip_corr,mom->E(),1); //----------------------------------------------------------------------------- // fill track histograms //----------------------------------------------------------------------------- TLorentzVector* tmom; int it = Ele->TrackNumber(); if (it >= 0) { TStnTrack* trk = fTrackBlock->Track(it); tmom = trk->Momentum(); Hist.fTIso->Fill(trk->Iso4()); Hist.fTrackD0->Fill(trk->D0()); Hist.fTrackD0Corr->Fill(TStntuple::CorrectedD0(trk)); Hist.fTrackZ0->Fill(trk->Z0()); Hist.fTrackChi2->Fill(trk->Chi2()/(trk->NCotHitsTot()+trk->NSvxHits()-4.9999)); Hist.fTrackCotChi2->Fill(trk->Chi2Cot()/(trk->NCotHitsTot()-4.9999)); Hist.fTrackNCotHitsTot->Fill(trk->NCotHitsTot()); Hist.fTrackNCotHitsAx->Fill(trk->NCotHitsAx()); Hist.fTrackNCotHitsSt->Fill(trk->NCotHitsSt()); Hist.fNSvxHits->Fill(trk->NSvxHits()); Hist.fNSvxRPhiHits->Fill(trk->NSvxRPhiHits()); Hist.fNSvxSASHits->Fill(trk->NSvxSASHits()); Hist.fNSvxZHits->Fill(trk->NSvxZHits()); //----------------------------------------------------------------------------- // check my extrapolation //----------------------------------------------------------------------------- TTrajectoryPoint p0; double xyz[8], xw, zw, ptot; int trk_charge, side, wedge; xyz[0] = trk->D0()*sin(trk->Phi0()); xyz[1] = trk->D0()*cos(trk->Phi0()); xyz[2] = trk->Z0(); ptot = tmom->P(); xyz[3] = tmom->Px()/ptot; xyz[4] = tmom->Py()/ptot; xyz[5] = tmom->Pz()/ptot; xyz[6] = 0; xyz[7] = ptot; p0.SetPoint(xyz); trk_charge = (int) trk->Charge(); fExtrapolator->SwimToCes(&p0,trk_charge,side,wedge,xw,zw); //----------------------------------------------------------------------------- // plot distributions for the delta's : my-bob //----------------------------------------------------------------------------- double bobs_x, bobs_z; if (side == 1) { bobs_x = Ele->TrackXCes(); bobs_z = Ele->TrackZCes(); } else { bobs_x = -Ele->TrackXCes(); bobs_z = -Ele->TrackZCes(); } Hist.fExtDx->Fill(xw-bobs_x); Hist.fExtDz->Fill(zw-bobs_z); } else { Hist.fTIso->Fill(1e6); Hist.fTrackD0->Fill(1e6); Hist.fTrackD0Corr->Fill(1.e6); Hist.fTrackZ0->Fill(1.e6); Hist.fTrackChi2->Fill(1.e6); Hist.fTrackCotChi2->Fill(1.e6); Hist.fTrackNCotHitsTot->Fill(-1); Hist.fTrackNCotHitsAx ->Fill(-1); Hist.fTrackNCotHitsSt ->Fill(-1); Hist.fNSvxHits ->Fill(-1); Hist.fNSvxRPhiHits->Fill(-1); Hist.fNSvxSASHits ->Fill(-1); Hist.fNSvxZHits ->Fill(-1); Hist.fExtDx->Fill(1.e6); Hist.fExtDz->Fill(1.e6); } //----------------------------------------------------------------------------- // ID bits //----------------------------------------------------------------------------- int id_word = Ele->IDWord(); for (int bit=0; bit<32; bit++) { if (((id_word >> bit) & 0x1) == 1) { Hist.fFailedBits->Fill(bit); } } } //_____________________________________________________________________________ void TWenuMonModule::FillEScaleHistograms(EScaleHist_t& Hist, TStnElectron* Ele) { const TLorentzVector* mom = Ele->Momentum(); float ele_eta = mom->Eta(); float ele_phi = TVector2::Phi_0_2pi(mom->Phi()); float EoverP = Ele->EOverP(); //EoverP CEM if (fabs(ele_eta) < 1.0) { Hist.fEoverP_inc->Fill(EoverP); if (ele_eta > 0. && ele_phi < M_PI) Hist.fEoverP_NE->Fill(EoverP); if (ele_eta > 0. && ele_phi > M_PI) Hist.fEoverP_SE->Fill(EoverP); if (ele_eta < 0. && ele_phi < M_PI) Hist.fEoverP_NW->Fill(EoverP); if (ele_eta < 0. && ele_phi > M_PI) Hist.fEoverP_SW->Fill(EoverP); } } //_____________________________________________________________________________- void TWenuMonModule::FillEScaleHistograms(EScaleHist_t& Hist, TStnElectron* E1, TStnElectron* E2) { static TLorentzVector zmom; zmom = *E1->Momentum(); zmom += *E2->Momentum(); double mass = zmom.M(); Hist.fZMass_inc->Fill(mass); if (E1->IsCentral() && E2->IsCentral()) Hist.fZMass_CC->Fill(mass); if ( (E1->IsCentral() && E2->IsPlug()) || (E2->IsCentral() && E1->IsPlug()) ) { Hist.fZMass_CP->Fill(mass); TStnElectron* plug_ele = E1; if (E2->IsPlug()) plug_ele = E2; if (plug_ele->Momentum()->Eta() < 0.) Hist.fZMass_CPW->Fill(mass); else Hist.fZMass_CPE->Fill(mass); } } //_____________________________________________________________________________ int TWenuMonModule::Debug() { char msg[200]; int tight_id_word, loose_id_word; if (PrintLevel() == 1) { GetHeaderBlock()->Print(Form("%s: ALL the events",GetName())); return 0; } if ((PrintLevel() == 2) && GetPassed()) { //----------------------------------------------------------------------------- // print passed events //----------------------------------------------------------------------------- GetHeaderBlock()->Print(Form("%s:002: all PASSED events",GetName())); return 0; } if ((PrintLevel() == 3) && (! GetPassed())) { //----------------------------------------------------------------------------- // print events with MET > fMinMet //----------------------------------------------------------------------------- GetHeaderBlock()->Print(Form("%s:003: all REJECTED events",GetName())); return 0; } if ((PrintLevel() == 101) && (fNTightElectrons > 0)) { //----------------------------------------------------------------------------- // events with at least one tight electron //----------------------------------------------------------------------------- GetHeaderBlock()->Print(Form("%s:101: N(tight electrons) = %2i", GetName(),fNTightElectrons)); return 0; } if (PrintLevel() == 201) { //----------------------------------------------------------------------------- // events failing filter cuts //----------------------------------------------------------------------------- if ( ! GetPassed()) { sprintf(msg,"%s:%4i: filter failed: n(tight)=%i, n(loose)=%i", GetName(),PrintLevel(),fNTightElectrons,fNLooseElectrons); GetHeaderBlock()->Print(msg); return 0; } } return 0; } //_____________________________________________________________________________ int TWenuMonModule::Event(int ientry) { // TLorentzVector* mom; // Double_t ff; Int_t nemo; TStnTrack *seed; TStnHeaderBlock *h; h = GetHeaderBlock(); //----------------------------------------------------------------------------- // check the trigger path //----------------------------------------------------------------------------- fTriggerBlock->GetEntry(ientry); int passed; if (h->McFlag() == 0) { passed = TStntuple::CheckL3TriggerPath(fTriggerBlock,fListOfL3Triggers); } else { // do not check L3... passed = 1; } //----------------------------------------------------------------------------- // always fill histogram for the run number //----------------------------------------------------------------------------- fHist.fRunNumber->Fill(h->RunNumber()); fHist.fFilterResult->Fill(passed); if (! passed) return 0; //----------------------------------------------------------------------------- // read the necessary data //----------------------------------------------------------------------------- fElectronBlock->GetEntry(ientry); fTrackBlock->GetEntry(ientry); fMetBlock->GetEntry(ientry); // do whatever you want if (PrintLevel() == 1) { fElectronBlock->Print(); } nemo = fElectronBlock->NElectrons(); //----------------------------------------------------------------------------- // dont forget to clear the list //----------------------------------------------------------------------------- fListOfGoodElectrons->Clear(); fListOfLooseElectrons->Clear(); fNTightElectrons = 0; fNLooseElectrons = 0; for (int i=0; iElectron(i); seed = TStntuple::ElectronTrack(ele,fTrackBlock); ele->SetTrack(seed); //----------------------------------------------------------------------------- // check tight ID cuts //----------------------------------------------------------------------------- fIdWord[i] = fTightID->IDWord(ele); ele->SetIdWord(fIdWord[i]); //----------------------------------------------------------------------------- // set 0: histograms for ALL EM objects //----------------------------------------------------------------------------- FillElectronHistograms(fHist.fEle[0],ele); //----------------------------------------------------------------------------- // check loose ID cuts //----------------------------------------------------------------------------- fLooseIdWord[i] = fLooseID->IDWord(ele); if (fIdWord[i] == 0) { //----------------------------------------------------------------------------- // set 1: GOOD electrons //----------------------------------------------------------------------------- fNTightElectrons++; fListOfGoodElectrons->Add(ele); FillElectronHistograms(fHist.fEle[1],ele); if (fMetBlock->Met(1) > 15.) FillEScaleHistograms(fHist.fEScaleHist, ele); } if (fLooseIdWord[i] == 0) { //----------------------------------------------------------------------------- // LOOSE electrons, an electron can pass both tight and loose cuts //----------------------------------------------------------------------------- fNLooseElectrons++; fListOfLooseElectrons->Add(ele); FillElectronHistograms(fHist.fEle[2],ele); } //----------------------------------------------------------------------------- // histograms for electrons with IO tracks (algorithm # 3) //----------------------------------------------------------------------------- if (seed != 0) { if (seed->Algorithm() == 3) { FillElectronHistograms(fHist.fEle[3],ele); } } } //----------------------------------------------------------------------------- // event histograms //----------------------------------------------------------------------------- if (fNTightElectrons > 0) { FillEventHistograms(fHist.fEventHist); } //----------------------------------------------------------------------------- // 0. tight-(>=loose) pairs, opposite signs //----------------------------------------------------------------------------- for (int i1=0; i1Electron(i1); for (int i2=0; i2Electron(i2); if (e1->Charge() != e2->Charge()) { if (fIdWord[i2] == 0) { // e2 is also tight, avoid double counting if (i2 > i1) { FillEEHistograms(fHist.fEEHist[0],e1,e2); FillEScaleHistograms(fHist.fEScaleHist,e1,e2); } } else if (fLooseIdWord[i2] == 0) { // e2 is loose FillEEHistograms(fHist.fEEHist[0],e1,e2); } } } } } //----------------------------------------------------------------------------- // 4. tight-(>=loose) pairs, same sign //----------------------------------------------------------------------------- for (int i1=0; i1Electron(i1); for (int i2=0; i2Electron(i2); if (e1->Charge() == e2->Charge()) { if (fIdWord[i2] == 0) { // e2 is also tight, avoid double counting if (i2 > i1) { FillEEHistograms(fHist.fEEHist[1],e1,e2); } } else if (fLooseIdWord[i2] == 0) { // e2 is loose FillEEHistograms(fHist.fEEHist[1],e1,e2); } } } } } //----------------------------------------------------------------------------- // filtering part //----------------------------------------------------------------------------- passed = ((fNTightElectrons >= fMinNTightElectrons) && (fNTightElectrons < fMaxNTightElectrons) && (fNLooseElectrons >= fMinNLooseElectrons) && (fNLooseElectrons < fMaxNLooseElectrons) && (fNEmObjects >= fMinNEmObjects ) && (fNEmObjects < fMaxNEmObjects ) ); SetPassed(passed); //----------------------------------------------------------------------------- // debugging part //----------------------------------------------------------------------------- Debug(); return 0; } //_____________________________________________________________________________ int TWenuMonModule::EndJob() { printf("----- end job: ---- %s\n",GetName()); return 0; } //_____________________________________________________________________________ void TWenuMonModule::PlotHistograms(int run_number, int slide) { // plot slides char name[120], canvas_name[120], title[120], pad_name[120]; sprintf(name,"run_%i_%i",run_number,slide); sprintf(title,"run %i slide %i ",run_number, slide); sprintf(canvas_name,"%s_%s",GetName(),name); sprintf(pad_name,"%s_p1",canvas_name); if (slide == 1) { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- // TPostScript ps("l1ana.ps",-111); TCanvas* c = NewSlide(name,title,2,3); TPad* p1 = (TPad*) c->GetPrimitive(pad_name); p1->cd(1); fHist.fEle[1].fEtVsEta->Draw(); gPad->Update(); } else if (slide == 2) { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- // TPostScript ps("l1ana.ps",-111); TCanvas* c = NewSlide(name,title,2,3); TPad* p1 = (TPad*) c->GetPrimitive(pad_name); p1->cd(1); fHist.fEle[1].fIso->Draw(); gPad->Update(); } }