Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:45

0001 /*
0002  * This macro shows a minimum working example of running the tracking
0003  * hit unpackers with some basic seeding algorithms to try to put together
0004  * tracks. There are some analysis modules run at the end which package
0005  * hits, clusters, and clusters on tracks into trees for analysis.
0006  */
0007 
0008 #include <fun4all/Fun4AllUtils.h>
0009 // #include <G4_ActsGeom.C>
0010 // #include <G4_Global.C>
0011 // #include <G4_Magnet.C>
0012 // #include <G4_Mbd.C>
0013 #include <GlobalVariables.C>
0014 // #include <QA.C>
0015 // #include <Trkr_Clustering.C>
0016 // #include <Trkr_Reco.C>
0017 // #include <Trkr_RecoInit.C>
0018 #include <Trkr_TpcReadoutInit.C>
0019 
0020 #include <cdbobjects/CDBTTree.h>
0021 #include <ffamodules/CDBInterface.h>
0022 // #include <fun4all/Fun4AllDstInputManager.h>
0023 // #include <fun4all/Fun4AllDstOutputManager.h>
0024 // #include <fun4all/Fun4AllInputManager.h>
0025 // #include <fun4all/Fun4AllOutputManager.h>
0026 // #include <fun4all/Fun4AllRunNodeInputManager.h>
0027 // #include <fun4all/Fun4AllServer.h>
0028 
0029 #include <phool/recoConsts.h>
0030 
0031 // #include <trackingqa/InttClusterQA.h>
0032 // #include <trackingqa/MicromegasClusterQA.h>
0033 // #include <trackingqa/MvtxClusterQA.h>
0034 // #include <trackingqa/TpcClusterQA.h>
0035 // 
0036 // #include <trackingdiagnostics/TrackResiduals.h>
0037 // #include <trackingdiagnostics/TrkrNtuplizer.h>
0038 
0039 #include <stdio.h>
0040 
0041 // #include <collect/Collect.h>
0042 
0043 //R__LOAD_LIBRARY(libfun4all.so)
0044 //R__LOAD_LIBRARY(libffamodules.so)
0045 //R__LOAD_LIBRARY(libmvtx.so)
0046 //R__LOAD_LIBRARY(libintt.so)
0047 R__LOAD_LIBRARY(libtpc.so)
0048 //R__LOAD_LIBRARY(libmicromegas.so)
0049 //R__LOAD_LIBRARY(libTrackingDiagnostics.so)
0050 //R__LOAD_LIBRARY(libtrackingqa.so)
0051 R__LOAD_LIBRARY(libphool.so)
0052 R__LOAD_LIBRARY(libcdbobjects.so)
0053 //R__LOAD_LIBRARY(libcollect.so)
0054 
0055 double driftGET( const int arun = 51279 );
0056 bool CheckHV( const int arun = 51279 );
0057 
0058 using std::cout;
0059 using std::endl;
0060 
0061 //------------------------------------------------------------------------
0062 //  get drift velocity from cdb...  wjl aug 2024
0063 //
0064 void drift(){
0065 
0066 //  ~70 um/ns -> 0.007 in sphenix units
0067 
0068     TGraph *gdriftrun   = new TGraph();
0069             gdriftrun   ->SetMarkerStyle(20);
0070             gdriftrun   ->SetMarkerSize(0.9);
0071             gdriftrun   ->SetMarkerColor(kBlue);
0072             gdriftrun   ->SetLineColor(kBlue);
0073 
0074     double drifts[2000] = {0};
0075     const int NPHASE = 9;
0076     int iphase = 0;
0077     const char* phasename[NPHASE]   = {"6x6","28x28","56x56","111x111 8/9","111x111 8/11","","BP#downarrow","",""};
0078     int    lastruns[NPHASE] = {49722,50025,50458,50936,51109,51191,51301,51495,51617};
0079     double phaseN[NPHASE]   = {0};
0080     double phaseA[NPHASE]   = {0};
0081     double phaseNhv[NPHASE] = {0};
0082     double phaseAhv[NPHASE] = {0};
0083     double lowest[NPHASE]   = {0};
0084     for (int iph=0;iph<NPHASE;iph++){ lowest[iph] = 99.; }
0085 
0086     //---- loop over run numbers...
0087     //
0088     for (int i=0;i<2000;i++){
0089         //
0090         int irun    = 49700+i;
0091         double val  = driftGET(irun);
0092         //
0093         if (irun<=49722){ iphase=0; } else
0094         if (irun<=50025){ iphase=1; } else
0095         if (irun<=50458){ iphase=2; } else
0096         if (irun<=50936){ iphase=3; } else
0097         if (irun<=51109){ iphase=4; } else
0098         if (irun<=51191){ iphase=5; } else
0099         if (irun<=51301){ iphase=6; } else 
0100         if (irun<=51495){ iphase=7; } else 
0101                         { iphase=8; } 
0102         //
0103         bool CorrectHV  = CheckHV(irun);
0104         //
0105         drifts[i]   = val;
0106         if (val>0.){
0107             gdriftrun   ->SetPoint(gdriftrun->GetN(),irun,val);
0108             phaseA[iphase]  += val;
0109             phaseN[iphase]  += 1.0;
0110 //          if (CorrectHV){
0111 //              phaseAhv[iphase]    += val;
0112 //              phaseNhv[iphase]    += 1.0;
0113 //          }
0114             if (val<lowest[iphase]) lowest[iphase]=val;
0115         }
0116     }
0117     
0118     int nrunstot    = 0;
0119     int nrunstothv  = 0;
0120     for (int iph=0;iph<NPHASE;iph++){
0121         if (phaseN[iph]>0){
0122             nrunstot        += phaseN[iph];
0123             nrunstothv      += phaseNhv[iph];
0124             phaseA[iph]     /= phaseN[iph];
0125 //          phaseAhv[iph]   /= phaseNhv[iph];
0126 //          cout<<"RunNum<="<<lastruns[iph]<<"\t Nruns="<<phaseN[iph]<<" "<<phaseNhv[iph]<<"\t <v>="<<phaseA[iph]<<endl;
0127         }
0128     }
0129     cout<<"Nruns with custom <v> found = "<<nrunstot<<endl;
0130         
0131     //---- paint setup
0132     int ican=-1,itext=-1,iline=-1,ivline=-1,iframe=-1; 
0133     TCanvas *ccan[100];
0134     TH1F    *frame[100];
0135     TLatex  *text[1000];
0136     TLine   *line[100];
0137     TLine   *vline[100];
0138     for (int i=0;i<1000;i++){
0139         text[i] = new TLatex();
0140         text[i] ->SetNDC();
0141         text[i] ->SetTextFont(42);
0142         text[i] ->SetTextSize(0.05);
0143         text[i] ->SetTextAlign(33);
0144         line[i] = new TLine();
0145         line[i] ->SetLineColor(1);
0146         line[i] ->SetLineStyle(2);
0147         line[i] ->SetLineWidth(2);
0148         vline[i]= new TLine(0,-1,0,1);
0149         vline[i]->SetLineColor(17);
0150         vline[i]->SetLineWidth(2);
0151     }
0152     gROOT->SetStyle("Modern");
0153     gStyle->SetOptStat(0);
0154     gStyle->SetTitleAlign(13);
0155     gStyle->SetTitleFontSize(0.08);     
0156     gStyle->SetTitleX(0.20);
0157     gStyle->SetTitleY(0.98);
0158     gStyle->SetPadRightMargin(0.01);
0159     gStyle->SetPadTopMargin(0.01);
0160     gStyle->SetPadBottomMargin(0.08);
0161     gStyle->SetPadLeftMargin(0.12);
0162     gStyle->SetTitleSize(0.03,"xyzt");
0163     gStyle->SetLabelSize(0.03,"xyzt");
0164     //
0165     //---- end paint setup..
0166 
0167     //---- paint...
0168     //  
0169     ++ican; ccan[ican]  = new TCanvas(Form("ccan%d",ican),Form("ccan%d",ican),20+ican*30,30+ican*30,0.7*1100,0.7*850);
0170     ccan[ican]->cd(); ccan[ican]->Divide(1,1,0.0001,0.0001);
0171         ccan[ican]->cd(1);
0172         gdriftrun->Draw("AP");
0173         for (int iph=0;iph<NPHASE;iph++){
0174             ++itext; text[itext]->SetNDC(kFALSE); text[itext]->SetTextAlign(23); text[itext]->SetTextSize(0.03); 
0175                 text[itext]->DrawLatex(lastruns[iph]-20,0.996*lowest[iph],Form("%.5f",phaseA[iph]));
0176             //++itext; text[itext]->SetNDC(kFALSE); text[itext]->SetTextAlign(23); text[itext]->SetTextSize(0.03); text[itext]->SetTextColor(kGreen+1); 
0177             //  text[itext]->DrawLatex(lastruns[iph],0.996*lowest[iph]-0.00005,Form("%.5f",phaseAhv[iph]));
0178             //
0179             ++itext; text[itext]->SetNDC(kFALSE); text[itext]->SetTextAlign(21); text[itext]->SetTextSize(0.03); 
0180                 text[itext]->SetTextAngle(90);
0181                 text[itext]->DrawLatex(lastruns[iph],0.0067,Form("%s",phasename[iph]));
0182         }
0183     ccan[ican]->cd(); ccan[ican]->Update();
0184     ccan[ican]->Print("drift.ps(");
0185     
0186     //---- close-out...
0187     //
0188     ccan[ican]->Print("drift.ps]");
0189     int iSuccess = gSystem->Exec("ps2pdf drift.ps drift.pdf");
0190     cout<<"isuccess="<<iSuccess<<endl;
0191     if (iSuccess==-1){
0192         cout<<"drift.pdf produced, deleting drift.ps file..."<<endl;
0193         TString sexec    = TString("/bin/rm drift.ps");
0194         cout<<sexec.Data()<<endl;
0195         gSystem         ->Exec(sexec.Data());
0196     }
0197     cout<<"Done..."<<endl;
0198     
0199     cout<<"Writing drift.root..."<<endl;
0200     TFile *fout = new TFile("drift.root","RECREATE");
0201         fout->cd();
0202         gdriftrun->Write("gdriftrun");
0203     fout->Close();
0204         
0205 }
0206 
0207 //------------------------------------------------------------
0208 //
0209 //  return true if HV=3.3 kV
0210 //
0211 bool CheckHV( const int irun = 51279 ){
0212     if (irun>=49706&&irun<=49713){ return true; } else
0213     if (irun>=50006&&irun<=50014){ return true; } else
0214     if (irun>=50021&&irun<=50025){ return true; } else
0215     if (irun>=50438&&irun<=50440){ return true; } else
0216     if (irun>=50444&&irun<=50449){ return true; } else
0217     if (irun>=50916&&irun<=50921){ return true; } else
0218     if (irun>=50933&&irun<=50936){ return true; } else
0219     if (irun>=51099&&irun<=51107){ return true; }
0220 //  if (irun>=&&irun<=){ return true; } else
0221 //  if (irun>=&&irun<=){ return true; } else
0222 //  if (irun>=&&irun<=){ return true; } else
0223 //  if (irun>=&&irun<=){ return true; } else
0224     return false;
0225 }
0226 
0227 //-----------------------------------------------------------
0228 //
0229 double driftGET( const int runnumber = 51279 ){
0230     //
0231     TpcReadoutInit( runnumber );
0232     double driftOLD = G4TPC::tpc_drift_velocity_reco;
0233     //
0234     auto rc = recoConsts::instance();
0235     rc->set_IntFlag("RUNNUMBER", runnumber);
0236     //  
0237     Enable::CDB = true;
0238     rc->set_StringFlag("CDB_GLOBALTAG", "ProdA_2024");
0239     rc->set_uint64Flag("TIMESTAMP", 6);
0240     //
0241     //G4TPC::tpc_drift_velocity_reco = (8.0 / 1000) * 107.0 / 105.0;
0242     //
0243     //---- get drift velocity
0244     double driftCDB = 0;
0245     rc->set_uint64Flag("TIMESTAMP",runnumber);
0246     CDBInterface* cdb = CDBInterface::instance();           
0247     std::string tpc_dv_calib_dir = cdb->getUrl("TPC_DRIFT_VELOCITY");
0248     if (!tpc_dv_calib_dir.empty()){         // path to driftvelocity calib file was found...
0249         //cout << "DRIFT: Path of tpc_drift_velocity_calib_file = "<< tpc_dv_calib_dir << endl;
0250         CDBTTree *cdbttree = new CDBTTree(tpc_dv_calib_dir);
0251         cdbttree->LoadCalibrations();
0252         driftCDB    = cdbttree->GetSingleFloatValue("tpc_drift_velocity");
0253         cout<<"DRIFT: RunNum="<<runnumber<<"\t driftOLD=" << driftOLD << "\t driftCDB=" << driftCDB << endl;
0254         //if (driftCDB>0.&&driftCDB<0.01){
0255         //  G4TPC::tpc_drift_velocity_reco  = driftCDB;
0256         //}
0257     } else {
0258         //cout << "DRIFT: Path to tpc_drift_velocity_calib_file NOT FOUND...."<< endl;
0259     }
0260     //
0261     return driftCDB;
0262 }
0263