Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:15:08

0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <map>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "TChain.h"
0008 #include "TFile.h"
0009 #include "TTree.h"
0010 #include "TString.h"
0011 #include "TObjString.h"
0012 #include "TSystem.h"
0013 #include "TROOT.h"
0014 #include "TTreeReader.h"
0015 #include "TTreeReaderValue.h"
0016 #include "TTreeReaderArray.h"
0017 #include "TVector3.h"
0018 
0019 #include <boost/format.hpp>
0020 #include <boost/math/special_functions/sign.hpp>
0021 
0022 /*************************************************************/
0023 /*               TPC Raw Data Event Display                  */
0024 /*               Thomas Marshall,Aditya Dash                 */
0025 /*        rosstom@ucla.edu,aditya55@physics.ucla.edu         */
0026 /*************************************************************/
0027 
0028 TVector3 getBinPosition(int sector, int inFee, int channel, double zPos, TTree* R1, TTree* R2, TTree* R3)
0029 {
0030   int mod_arr[26] = {2,2,1,1,1,3,3,3,3,3,3,2,2,1,2,2,1,1,2,2,3,3,3,3,3,3};
0031   float slot[26] = {5,6,1,3,2,12,10,11,9,8,7,1,2,4,8,7,6,5,4,3,1,3,2,4,6,5};
0032   TTreeReader* myReader;
0033   if (mod_arr[inFee] == 1)
0034   {
0035     myReader = new TTreeReader(R1);
0036   }
0037   else if (mod_arr[inFee] == 2)
0038   {
0039     myReader = new TTreeReader(R2);
0040   }
0041   else if (mod_arr[inFee] == 3)
0042   {
0043     myReader = new TTreeReader(R3);
0044   }
0045   TTreeReaderValue<Float_t> FEE(*myReader, "FEE");
0046   TTreeReaderValue<Int_t> FEE_Chan(*myReader, "FEE_Chan");
0047   //TTreeReaderValue<Double_t> x(myReader, "x");
0048   //TTreeReaderValue<Double_t> y(myReader, "y");
0049   TTreeReaderValue<Double_t> phi(*myReader, "phi");
0050   //TTreeReaderValue<Double_t> PadX(myReader, "PadX");
0051   //TTreeReaderValue<Double_t> PadY(myReader, "PadY");
0052   TTreeReaderValue<Double_t> PadR(*myReader, "PadR");
0053   //TTreeReaderValue<Double_t> PadPhi(myReader, "PadPhi");
0054 
0055   double phiOffset;
0056   if (sector < 12) phiOffset = 2*M_PI*((double)sector/12.) - 2*M_PI*(1./12.)/2;
0057   else phiOffset = 2*M_PI*(((double)sector-12.)/12.) - 2*M_PI*(1./12.)/2;
0058 
0059   while(myReader->Next())
0060   {
0061     if (slot[inFee]-1 == *FEE && channel == *FEE_Chan)
0062     {
0063       double x = (*PadR/10)*std::cos(*phi+phiOffset);
0064       double y = (*PadR/10)*std::sin(*phi+phiOffset);
0065       TVector3 pos;
0066       pos.SetX(x); pos.SetY(y); pos.SetZ(zPos);
0067       return pos; 
0068     }
0069   }
0070   TVector3 pos;
0071   pos.SetX(0); pos.SetY(0); pos.SetZ(0);
0072   return pos;
0073 }
0074 
0075 
0076 void TPCEventDisplay(const float adcCut = 85., 
0077                      const string &outfile = "/sphenix/user/rosstom/test/TPCEventDisplay_10169.json", 
0078                      const string &indir = "/sphenix/user/rosstom/test/testFiles/", 
0079                      const string &runName = "pedestal-00010169"){
0080   
0081   std::ofstream outdata;
0082   outdata.open(outfile.c_str());
0083   if( !outdata ) { // file couldn't be opened
0084       cerr << "ERROR: file could not be opened" << endl;
0085       exit(1);
0086   }
0087 
0088   outdata << "{\n    \"EVENT\": {\n        \"runid\": 1, \n        \"evtid\": 1, \n        \"time\": 0, \n        \"type\": \"Collision\", \n        \"s_nn\": 0, \n        \"B\": 3.0,\n        \"pv\": [0,0,0]  \n    },\n" << endl;
0089 
0090   outdata << "    \"META\": {\n       \"HITS\": {\n          \"INNERTRACKER\": {\n              \"type\": \"3D\",\n              \"options\": {\n              \"size\": 5,\n              \"color\": 16777215\n              } \n          },\n" << endl;
0091   outdata << "          \"TRACKHITS\": {\n              \"type\": \"3D\",\n              \"options\": {\n              \"size\": 5,\n              \"transparent\": 0.5,\n              \"color\": 16777215\n              } \n          },\n" << endl;
0092   outdata << "    \"JETS\": {\n        \"type\": \"JET\",\n        \"options\": {\n            \"rmin\": 0,\n            \"rmax\": 78,\n            \"emin\": 0,\n            \"emax\": 30,\n            \"color\": 16777215,\n            \"transparent\": 0.5 \n        }\n    }\n        }\n    }\n," << endl;
0093   outdata << "    \"HITS\": {\n        \"CEMC\":[{\"eta\": 0, \"phi\": 0, \"e\": 0}\n            ],\n        \"HCALIN\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n            ],\n        \"HCALOUT\": [{\"eta\": 0, \"phi\": 0, \"e\": 0}\n \n            ],\n\n" << endl;
0094   outdata << "    \"TRACKHITS\": [\n\n ";
0095 
0096   TTree *R1 = new TTree("R1","TPC Sector Mapping for R1");
0097   TTree *R2 = new TTree("R2","TPC Sector Mapping for R1");
0098   TTree *R3 = new TTree("R3","TPC Sector Mapping for R1");
0099 
0100   R1->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R1-RevA.sch.ChannelMapping.csv",
0101                "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",','); 
0102   R2->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv",
0103                "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",','); 
0104   R3->ReadFile("/sphenix/u/rosstom/calibrations/TPC/Mapping/PadPlane/AutoPad-R3-RevA.sch.ChannelMapping.csv",
0105                "Entry/I:Radius/I:Pad/I:U/I:G/I:Pin/C:PinColID/I:PinRowID/I:PadName/C:FEE/F:FEE_Connector/C:FEE_Chan/I:phi/D:x/D:y/D:PadX/D:PadY/D:PadR/D:PadPhi/D",','); 
0106  
0107   bool firstClus = true;
0108 
0109   for (int q = 0; q < 24; q++)
0110   {
0111     cout << "Processing sector " << q << endl;
0112 
0113     string sectorNumber;
0114     if (q < 10) sectorNumber = "0"+std::to_string(q);
0115     else sectorNumber = std::to_string(q);   
0116 
0117     string fileName = indir+"TPC_ebdc"+sectorNumber+"_"+runName+"-0000.prdf_TPCRawDataTree.root";
0118 
0119     TFile *TPCFile = TFile::Open(fileName.c_str());
0120     TTreeReader myReader("SampleTree", TPCFile);
0121 
0122     TTreeReaderValue<Int_t> nSamples(myReader, "nSamples");
0123     TTreeReaderValue<Int_t> fee(myReader, "fee");
0124     TTreeReaderArray<UShort_t> adcSamples(myReader, "adcSamples");
0125     TTreeReaderValue<Int_t> Channel(myReader, "Channel");
0126 
0127     while(myReader.Next())
0128     {
0129       int mod_arr[26]={2,2,1,1,1,3,3,3,3,3,3,2,2,1,2,2,1,1,2,2,3,3,3,3,3,3};
0130       
0131       if (*nSamples <= 1) continue;
0132       
0133       float adcMax = 0;
0134       float adcMaxPos = 0;
0135       for(int adc_sam_no=0;adc_sam_no<*nSamples;adc_sam_no++)
0136       {
0137         if (adc_sam_no == 0)
0138     {
0139       adcMax = adcSamples[adc_sam_no];
0140       adcMaxPos = adc_sam_no;
0141     }
0142         else
0143         {
0144       if (adcSamples[adc_sam_no] > adcMax)
0145       {
0146         adcMax = adcSamples[adc_sam_no];
0147             adcMaxPos = adc_sam_no;
0148       }
0149         }
0150       }
0151       if (adcMax > adcCut)
0152       {
0153     double zPos;
0154     if (q < 12)
0155     {
0156       zPos = 105. - (adcMaxPos/((double)*nSamples-1.))*105.; 
0157     }
0158         else
0159     {
0160           zPos = -105. + (adcMaxPos/((double)*nSamples-1.))*105.;
0161     }
0162         TVector3 binXYZ = getBinPosition(q,*fee,*Channel,zPos,R1,R2,R3);
0163 
0164         TVector3 zeroVec;
0165         zeroVec.SetX(0);zeroVec.SetY(0);zeroVec.SetZ(0);
0166         if (binXYZ == zeroVec) continue;    
0167     
0168         stringstream spts;
0169         
0170         if (firstClus) firstClus = false;
0171         else spts << ",";
0172 
0173         spts << "{ \"x\": ";
0174         spts << binXYZ.x();
0175         spts << ", \"y\": ";
0176         spts << binXYZ.y();
0177         spts << ", \"z\": ";
0178         spts << binXYZ.z();
0179         spts << ", \"e\": ";
0180         spts << adcMax;
0181         spts << "}";
0182 
0183         outdata << (boost::format("%1%") % spts.str());
0184         spts.clear();
0185         spts.str("");
0186       } 
0187     }
0188   }
0189   outdata << "],\n    \"JETS\": [\n         ]\n    }," << endl;
0190   outdata << "\"TRACKS\": {" << endl;
0191   outdata <<"\""<<"INNERTRACKER"<<"\": [";
0192   outdata << "]" << endl;
0193   outdata << "}" << endl;
0194   outdata << "}" << endl; 
0195  
0196   outdata.close();     
0197 }