|
//____________________________________________________________________ // // Module for pedestal calibration of beam-beam counters // //____________________________________________________________________ // // $Id: BrBbVertexCalModule.cxx,v 1.3 2002/03/21 15:04:44 ouerdane Exp $ // $Author: ouerdane $ // $Date: 2002/03/21 15:04:44 $ // $Copyright: (C) 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov> // #ifndef BRAT_BrBbVertexCalModule #include "BrBbVertexCalModule.h" #endif #ifndef ROOT_TDirectory #include "TDirectory.h" #endif #ifndef ROOT_TF1 #include "TF1.h" #endif #ifndef ROOT_TString #include "TString.h" #endif #include <fstream.h> #ifndef WIN32 #include <iostream> #include <iomanip> #else #include <iostream.h> #include <iomanip.h> #endif #ifndef BRAT_BrRunInfoManager #include "BrRunInfoManager.h" #endif #ifndef BRAT_BrDetectorTrack #include "BrDetectorTrack.h" #endif #ifndef BRAT_BrPlane3D #include "BrPlane3D.h" #endif #ifndef BRAT_BrVector3D #include "BrVector3D.h" #endif #ifndef BRAT_BrLine3D #include "BrLine3D.h" #endif #ifndef BRAT_BrGeometryDbManager #include "BrGeometryDbManager.h" #endif //____________________________________________________________________ ClassImp(BrBbVertexCalModule); //____________________________________________________________________ BrBbVertexCalModule::BrBbVertexCalModule() { // Default constructor. DO NOT USE SetState(kSetup); fVtxOffset = 0; fBbVsTpc = 0; fBbVsTpc2d = 0; fHitModule = 0; fVertexModule = 0; } //____________________________________________________________________ BrBbVertexCalModule::BrBbVertexCalModule(const Char_t* name, const Char_t* title) : BrVertexCalModule(name, title) { // Named Constructor SetState(kSetup); fVtxOffset = 0; fBbVsTpc = 0; fBbVsTpc2d = 0; fHitModule = new BrBbCalHitsModule("BB", "BB Hit Module"); fVertexModule = new BrBbVertexModule( "BB", "BB Vertex Module"); SetDefaultParameters(); } //____________________________________________________________________ void BrBbVertexCalModule::SetDefaultParameters() { // set default parameters fHitModule->SetTreeOn(kFALSE); fHitModule->SetUseOldCal(kFALSE); fHitModule->SetMaxTdc(3800); fHitModule->SetMinTdc(10); fVertexModule->SetTreeOn(kFALSE); fVertexModule->SetMaxTimeDiff(0.5); fVertexModule->SetOffsetCalib(kTRUE); SetBigFitWindow(); // default is 5 cm (2 sigmas) SetSmallFitWindow(); // default is 1.4 cm (2 sigmas) SetFastFitWindow(); // default is 5 cm } //____________________________________________________________________ BrBbVertexCalModule::~BrBbVertexCalModule() { // destructor if (fHitModule) delete fHitModule; if (fVertexModule) delete fVertexModule; } //____________________________________________________________________ void BrBbVertexCalModule::DefineHistograms() { // Define histograms. They are: // <fill in here> if (fCommitAscii || fLoadAscii) { if (Verbose() > 10) Warning("DefineHistograms", "No need to be here if you " "load or commit an ascii calibration"); return; } if (GetState() != kInit) { Stop("DefineHistograms", "Must be called after Init"); return; } TDirectory* saveDir = gDirectory; // book sub module histos fHitModule->Book(); fVertexModule->Book(); fHistDir = gDirectory->mkdir("BB_VertexCal"); fHistDir->cd(); // Make histograms here fBbVsTpc = new TH1F* [3]; fBbVsTpc[0] = new TH1F("bigTubes", "Big tube vertex - TPM1 track vertices", 1000, -50, 50); fBbVsTpc[1] = new TH1F("smallTubes", "Small tube vertex - TPM1 track vertices", 1000, -50, 50); fBbVsTpc[2] = new TH1F("fastestTubes", "Fastest tube vertex - TPM1 track vertices", 1000, -50, 50); fBbVsTpc2d = new TH2F* [3]; fBbVsTpc2d[0] = new TH2F("bigTubes2d", "Big tube vertex - TPM1 track vertices", 500, -50, 50, 500, -50, 50); fBbVsTpc2d[1] = new TH2F("smallTubes2d", "Small tube vertex - TPM1 track vertices", 500, -50, 50, 500, -50, 50); fBbVsTpc2d[2] = new TH2F("fastestTubes2d", "Fastest tube vertex - TPM1 track vertices", 500, -50, 50, 500, -50, 50); fVtxOffset = new TH1F("offsets", "BB Vertex offsets: 1 big, 2 small, 3 fastest", 30, 0.5, 3.5); fVtxSigma = new TH1F("sigmas", "BB - TPM1 sigma: 1 big, 2 small, 3 fastest", 30, 0.5, 3.5); gDirectory = saveDir; } //____________________________________________________________________ void BrBbVertexCalModule::Init() { // Job-level initialisation SetState(kInit); // // Called once per session // Get detectorParameters. Inform the parameterElementManeger about // database tables to be used (i.e. filled). if(DebugLevel() > 2) cout << "Entering BrBbVertexCalModule::Init() for " << GetName() << endl; // initializing base class BrVertexCalModule::Init(); BrCalibration::EAccessMode mode = BrCalibration::kRead; if(fLoadAscii) mode = BrCalibration::kTransitional; else if (fSaveAscii || fCommitAscii) mode = BrCalibration::kWrite; else { Abort("Init", "You MUST either save to ascii, load from ascii " "or commit from ascii. Use the proper setter! " ); return; } fCalibration->Use("bbVertexOffset", mode, 6); if (!fLoadAscii && ! fCommitAscii) { // initialize hit and vertex modules fHitModule->Init(); fVertexModule->Init(); fHitModule->SetVerbose(Verbose()); fVertexModule->SetVerbose(Verbose()); fHitModule->SetDebugLevel(DebugLevel()); fVertexModule->SetDebugLevel(DebugLevel()); // get TPM1 volume BrGeometryDbManager* geo = BrGeometryDbManager::Instance(); fTpm1Volume = (BrDetectorVolume*)geo-> GetDetectorVolume("BrDetectorVolume", "TPM1"); } } //____________________________________________________________________ void BrBbVertexCalModule::Begin() { // Run-level initialisation SetState(kBegin); if(fLoadAscii){ ReadAscii(); return; } if (fCommitAscii) return; // check if histos are booked if (!HistBooked()) { Abort("Begin", "MUST book histograms for calibration to work"); return; } BrVertexCalibration::EBrCalException bad = BrVertexCalibration::kCalException; fCalibration->SetBbBigOffset(bad, bad); fCalibration->SetBbSmallOffset(bad, bad); fCalibration->SetBbFastOffset(bad, bad); fHitModule->Begin(); fVertexModule->Begin(); } //____________________________________________________________________ void BrBbVertexCalModule::Event(BrEventNode* inNode, BrEventNode* outNode) { // Per event method SetState(kEvent); // ------------------------------------------------------------------- // Get TPM1 tracks and BB vertex // project tracks to longitudinal plane (X = 0 plane) // fill histos with Z0 vs track proj Z and difference between those // quantities. // ------------------------------------------------------------------- if(DebugLevel() > 1) cout << "Entering Event() in BrBbVertexCalModule for " << GetName() << endl; if (fCommitAscii || fLoadAscii) return; // Get TPM1 tracks BrDataTable* trks = inNode->GetDataTable("DetectorTrack TPM1"); if (!trks) trks = outNode->GetDataTable("DetectorTrack TPM1"); if (!trks) { if (DebugLevel() > 2) Warning("Event", "No TPM1 tracks for this event"); return; } // call hit and vertex modules event methods fHitModule->Event(inNode, outNode); fVertexModule->Event(inNode, outNode); // Get BB Vertex BrBbVertex* bbs = (BrBbVertex*)outNode->GetObject("BB Vertex Small"); BrBbVertex* bbb = (BrBbVertex*)outNode->GetObject("BB Vertex Big"); BrBbVertex* bbf = (BrBbVertex*)outNode->GetObject("BB Vertex Fastest"); if (bbs) Process(bbs, trks); if (bbb) Process(bbb, trks); if (bbf) Process(bbf, trks); } //____________________________________________________________________ void BrBbVertexCalModule::Process(BrBbVertex* bb, BrDataTable* trks) { // private method // loop over tracks and project them to longitudinal plane // fill histograms BBZ0 - Z track proj. // plane at X = 0 BrPlane3D plane(0,0,0, 0,1,0, 0,0,1); for (Int_t t = 0; t < trks->GetEntries(); t++) { BrDetectorTrack* trk = (BrDetectorTrack*)trks->At(t); BrLine3D trkLine = fTpm1Volume->LocalToGlobal(trk->GetTrackLine()); BrVector3D proj = plane.GetIntersectionWithLine(trkLine); fBbVsTpc[bb->GetMethod()-1]->Fill(bb->GetZ0() - proj(2)); fBbVsTpc2d[bb->GetMethod()-1]->Fill(proj(2), bb->GetZ0()); } } //____________________________________________________________________ void BrBbVertexCalModule::Finish() { // Job-level finalisation SetState(kFinish); if(fLoadAscii) return; if (fCommitAscii) { ReadAscii(); return; } fHitModule->Finish(); fVertexModule->Finish(); TF1* fit = new TF1("fit", "gaus", 0., 1000.); for (UInt_t i = 0; i < 3; i++) { // fit distribution with gaussian if (fBbVsTpc[i]->GetEntries() == 0) continue; Int_t binAtMax = fBbVsTpc[i]->GetMaximumBin(); // bin number at max Axis_t maxZ = fBbVsTpc[i]->GetBinCenter(binAtMax); fit->SetParameters(fBbVsTpc[i]->GetMaximum(), maxZ, fBbVsTpc[i]->GetRMS()); fBbVsTpc[i]-> Fit("fit", "Q0", "", maxZ - fFitWindow[i], maxZ + fFitWindow[i]); Float_t mean = fit->GetParameter(1); Float_t sigma = fit->GetParameter(2); fVtxOffset->Fill(i+1, mean); fVtxSigma->Fill(i+1, sigma); BrVertexCalibration::EBrSubDetector sub = BrVertexCalibration::EBrSubDetector(i*2); fCalibration->SetVertexOffset(BrVertexCalibration::kBb, sub, mean, sigma); } fCalibration-> SetComment("bbVertexOffset", "Generated by BrBbVertexCalModule: " "fit with a gaussian function on Z0 - TPM1 track Z"); if (Verbose()) cout << " --------- BB vertices offsets with TPM1 ---------- " << endl << " Big tube offset : " << setw(8) << fCalibration->GetBbBigOffset() << " +/- " << setw(7) << fCalibration->GetBbBigSigma() << " cm " << endl << " Small tube offset : " << setw(8) << fCalibration->GetBbSmallOffset() << " +/- " << setw(7) << fCalibration->GetBbSmallSigma() << " cm " << endl << " Fastest tube offset : " << setw(8) << fCalibration->GetBbFastOffset() << " +/- " << setw(7) << fCalibration->GetBbFastSigma() << " cm " << endl; if (fSaveAscii) SaveAscii(); } //____________________________________________________________________ void BrBbVertexCalModule::SaveAscii() { // save pedestal to ascii file BrRunInfoManager* runMan = BrRunInfoManager::Instance(); Int_t* runs = runMan->GetRunNumbers(); Int_t nrun = runMan->GetNumberOfRuns(); BrVertexCalModule::SaveAscii(); ofstream file(fCalibFile.Data(), ios::out); file << "****************************************** " << endl; file << "* Calibration for BB counter " << GetName() << endl; file << "* BB vertex offsets along the beam line" << endl; file << "* Used events from run(s) "; for (Int_t r = 0; r < nrun; r++) file << runs[r] << " "; file << endl; file << "****************************************** " <<endl; file << "*" << endl; file << "* Big tubes | Small tubes | Fastest tubes " << endl; file << "* Offset - Sigma | Offset - Sigma | Offset - Sigma" << endl; file << "* --------------------------------------------------------" << endl << endl; file << setw(8) << setprecision(5) << fCalibration->GetBbBigOffset() << " " << setw(8) << setprecision(5) << fCalibration->GetBbBigSigma() << " " << setw(8) << setprecision(5) << fCalibration->GetBbSmallOffset() << " " << setw(8) << setprecision(5) << fCalibration->GetBbSmallSigma() << " " << setw(8) << setprecision(5) << fCalibration->GetBbFastOffset() << " " << setw(8) << setprecision(5) << fCalibration->GetBbFastSigma() << endl; file << "* --------------------------------------------------------" << endl << endl; } //____________________________________________________________________ void BrBbVertexCalModule::ReadAscii() { // save pedestal to ascii file BrVertexCalModule::SaveAscii(); ifstream file(fCalibFile.Data(), ios::in); if (!file) { Abort("ReadAscii", "File %s was not found", fCalibFile.Data()); return; } Float_t big, small, fast, sbig, ssmall, sfast; Char_t comment[256]; file.getline(comment, 256); while(comment[0] == '*') file.getline(comment, 256); file >> big >> sbig >> small >> ssmall >> fast >> sfast; if (DebugLevel() > 2) cout << " Values read in the file " << fCalibFile.Data() << endl << " " << setw(8) << big << " +/- " << setw(8) << sbig << endl << " " << setw(8) << small << " +/- " << setw(8) << ssmall << endl << " " << setw(8) << fast << " +/- " << setw(8) << sfast << endl; fCalibration->SetBbSmallOffset(small, ssmall); fCalibration->SetBbBigOffset(big, sbig); fCalibration->SetBbFastOffset(fast, sfast); fCalibration->SetComment("bbVertexOffset", fComment.Data()); } //____________________________________________________________________ void BrBbVertexCalModule::Print(Option_t* option) const { // Print module information // See BrModule::Print for options. // In addition this module defines the Option: // <fill in here> TString opt(option); opt.ToLower(); BrModule::Print(option); if (opt.Contains("d")) cout << endl << " Original author: Djamel Ouerdane" << endl << " Last Modifications: " << endl << " $Author: ouerdane $" << endl << " $Date: 2002/03/21 15:04:44 $" << endl << " $Revision: 1.3 $ " << endl << endl << "-------------------------------------------------" << endl; } //____________________________________________________________________ // // $Log: BrBbVertexCalModule.cxx,v $ // Revision 1.3 2002/03/21 15:04:44 ouerdane // added fComment member to base class module and method SetComment so that the user can set comments about the calibration at commit time // // Revision 1.2 2001/11/05 07:00:28 ouerdane // added the sigma info // // Revision 1.1 2001/11/02 10:58:46 ouerdane // Added new classes for automatic vertex offset finding. // The result is stored in BrVertexCalibration which corresponds // to a new entry in the SQL database called VERTEX (type BEAM) // (cf. data/calib/BrVertexCalibration for more details) // // The modules are: BrVertexCalModule (base class) // BrBbVertexCalModule for beam-beam counters // will come next: BrTpcVertexCalModule // BrZdcVertexCalModule // // The bb module uses internally the new cal hit and vertex modules with all offsets // set to 0. (of course). It only needs TPM1 tracks and a valid BB calibration // made with the wonderful BB calibration modules and stored into the SQL db :) // // Usage: once you've made a calibration and stored to the rcas0005 DB, use // the script scripts/calib/bb/BbVtxOffset.C to evaluate the BB vertices offsets // with TPM1. // The result will be stored into an ascii file that you can commit afterwards // (check first your histos !) // // The vertex module then will read these offsets so that you won't need to think about it! // // |
||||||
This page automatically generated by script docBrat by Christian Holm |
Copyright ; 2002 BRAHMS Collaboration
<brahmlib@rcf.rhic.bnl.gov>
|