#include <ParticleTrimmer.h>
Public Member Functions | |
| ParticleTrimmer () | |
| ~ParticleTrimmer () | |
| void | AddFiles (string file) |
| void | RunTrimmer () |
Private Member Functions | |
| void | trimPOT () |
| void | trimPRecord () |
Private Attributes | |
| TChain * | chain_precord |
| TChain * | chain_pot |
| PRecord * | precord |
| POT * | pot |
| POT * | totalpot |
| string | outfile |
| TFile * | out |
| int | nearFileTypeCount |
| int | farFileTypeCount [5] |
|
|
Definition at line 11 of file ParticleTrimmer.cxx. References chain_pot, chain_precord, out, pot, precord, POT::Reset(), and totalpot. 00012 {
00013 chain_precord=new TChain("PA");
00014 chain_pot=new TChain("pottree");
00015
00016 precord=new PRecord();
00017 pot=new POT();
00018 totalpot=new POT();
00019
00020 chain_precord->SetBranchAddress("PRecord",&precord);
00021 chain_pot->SetBranchAddress("ParticlePOT",&pot);
00022 totalpot->Reset();
00023
00024 out=0;
00025
00026 }
|
|
|
Definition at line 28 of file ParticleTrimmer.cxx. References out. 00029 {
00030 out->Close();
00031
00032 }
|
|
|
Definition at line 34 of file ParticleTrimmer.cxx. References chain_pot, and chain_precord. 00035 {
00036
00037
00038 int added = chain_precord->Add(file.c_str());
00039 chain_pot->Add(file.c_str());
00040 cout <<"Adding "<<added<<": "<<file<<"\n";
00041 }
|
|
|
Definition at line 43 of file ParticleTrimmer.cxx. References chain_precord, out, outfile, outfile, trimPOT(), and trimPRecord(). 00044 {
00045
00046
00047
00048
00049
00050 string file="";
00051 if(chain_precord->GetEntries() > 0){
00052 chain_precord->GetEntry(0);
00053 file = chain_precord->GetFile()->GetName();
00054 }
00055 string minifile = file.substr(file.find_last_of("/")+1, file.find_last_of(".root")-file.find_last_of("/") - 5);
00056 minifile += "-Trim.root";
00057
00058 outfile = minifile;
00059
00060 if(outfile == "-Trim.root"){
00061 cout<<"No input file found\n";
00062 return;
00063 }
00064
00065 cout<<"Setting output to "<<outfile<<"\n";
00066
00067 out=new TFile(outfile.c_str(),"RECREATE");
00068
00069 trimPOT();
00070 trimPRecord();
00071
00072 }
|
|
|
Definition at line 75 of file ParticleTrimmer.cxx. References POT::beamtype, beamtype, chain_pot, det, farFileTypeCount, nearFileTypeCount, POT::nruns, POT::nsnarls, out, POT::pot, pot, and totalpot. Referenced by RunTrimmer(). 00076 {
00077 printf("\nTrimming POTs\n");
00078
00079 nearFileTypeCount=0;
00080 farFileTypeCount[0]=0;
00081 farFileTypeCount[1]=0;
00082 farFileTypeCount[2]=0;
00083 farFileTypeCount[3]=0;
00084 farFileTypeCount[4]=0;
00085
00086 TTree *tree = new TTree("pottree","pottree");
00087 TTree::SetBranchStyle(1);
00088 TBranch* br = tree->Branch("ParticlePOT", &totalpot );
00089 br->SetAutoDelete(kFALSE);
00090
00091 int ent = (int)chain_pot->GetEntries();
00092 for(int i=0;i<ent;i++)
00093 {
00094 if(i%10000==0) cout << 100*float(i)/float(ent)
00095 << "% done\n";
00096 chain_pot->GetEntry(i);
00097
00098 string file="";
00099 file = chain_pot->GetFile()->GetName();
00100
00101 string minifile = file.substr(file.find_last_of("/")+1, file.find_last_of(".root")-file.find_last_of("/") - 5);
00102
00103 string filetype = minifile.substr(minifile.find_first_of("PO-")+3,4);
00104 printf("file type %s\n",filetype.c_str());
00105
00106
00107 string det = filetype.substr(0,1);
00108
00109 string beam = filetype.substr(3,4);
00110
00111 printf("%s %s\n",det.c_str(),beam.c_str());
00112
00113 if(det=="f")
00114 {
00115 int beamtype=-1;
00116 sscanf(beam.c_str(),"%d",&beamtype);
00117 farFileTypeCount[beamtype]++;
00118 }else if(det=="n" || det=="N" || det=="F") //far data is treated as near... (no adjustment)
00119 {
00120 nearFileTypeCount++;
00121 }
00122
00123
00124 printf("%d %f\n",i,pot->pot);
00125 totalpot->pot+=pot->pot;
00126 totalpot->nruns+=pot->nruns;
00127 totalpot->nsnarls+=pot->nsnarls;
00128 if(i==0)totalpot->beamtype=pot->beamtype;
00129 }
00130
00131 int farcnt=0;
00132 for(int i=0;i<5;i++)
00133 farcnt+=farFileTypeCount[i];
00134
00135 if(farcnt && nearFileTypeCount)
00136 {
00137 printf("attempting to trim files from both detectors!\n");
00138 exit(1);
00139 }
00140
00141 //don't be fancy.. require the same number of each far type
00142 if(farFileTypeCount[0]!=farFileTypeCount[3] || farFileTypeCount[0] != farFileTypeCount[4]
00143 || farFileTypeCount[3] != farFileTypeCount[4])
00144 {
00145 printf("need same number of each file type in far!\n");
00146 exit(1);
00147 }
00148
00149 if(farFileTypeCount[0])totalpot->pot/=farFileTypeCount[0];
00150
00151 tree->Fill();
00152 out->cd();
00153 tree->Write();
00154
00155
00156 }
|
|
|
Definition at line 158 of file ParticleTrimmer.cxx. References chain_precord, Event::contained, PRecord::event, farFileTypeCount, Event::inFiducial, PRecord::mctrue, out, precord, MCTrue::totbeamweight, and MCTrue::type. Referenced by RunTrimmer(). 00159 {
00160 printf("\nTrimming PRecords...\n");
00161
00162
00163 //calculate the adjustment for totbeamweight based on the number of files
00164
00165 double eventTypeAdj[5];
00166 for(int i=0;i<6;i++)eventTypeAdj[i]=1.;
00167
00168 if(nearFileTypeCount)
00169 {
00170 //do nothing...
00171 }else if(farFileTypeCount[0])
00172 {
00173 eventTypeAdj[0]=1./3.;
00174 }else{
00175 printf("no files found?\n");
00176 exit(1);
00177 }
00178
00179
00180 //
00181
00182 out->cd();
00183 TTree *tree = new TTree("PA","PA");
00184 TTree::SetBranchStyle(1);
00185 TBranch* br = tree->Branch("PRecord", &precord );
00186 br->SetAutoDelete(kFALSE);
00187
00188 int ent = (int)chain_precord->GetEntries();
00189
00190 printf("%d total entries\n",ent);
00191
00192 int totalpassed=0;
00193
00194 for(int i=0;i<ent;i++)
00195 {
00196
00197
00198 if(i%10000==0)
00199 { cout << 100*float(i)/float(ent)
00200 << "% done\n";
00201 tree->AutoSave("SaveSelf");
00202 }
00203
00204 chain_precord->GetEntry(i);
00205
00206 //some trimming
00207
00208 if(precord->event.inFiducial!=1)continue;
00209 if(precord->event.contained!=1)continue;
00210
00211 if(precord->mctrue.type<0 || precord->mctrue.type>4)continue;
00212
00213 precord->mctrue.totbeamweight*=eventTypeAdj[precord->mctrue.type];
00214
00215 tree->Fill();
00216 totalpassed++;
00217 }
00218
00219
00220 tree->AutoSave("SaveSelf");
00221 printf("kept %d of %d entries\n",totalpassed,ent);
00222 //dups trees?
00223 //tree->Write();
00224
00225
00226
00227 }
|
|
|
Definition at line 26 of file ParticleTrimmer.h. Referenced by AddFiles(), ParticleTrimmer(), and trimPOT(). |
|
|
Definition at line 25 of file ParticleTrimmer.h. Referenced by AddFiles(), ParticleTrimmer(), RunTrimmer(), and trimPRecord(). |
|
|
Definition at line 41 of file ParticleTrimmer.h. Referenced by trimPOT(), and trimPRecord(). |
|
|
Definition at line 40 of file ParticleTrimmer.h. Referenced by trimPOT(). |
|
|
Definition at line 38 of file ParticleTrimmer.h. Referenced by ParticleTrimmer(), RunTrimmer(), trimPOT(), trimPRecord(), and ~ParticleTrimmer(). |
|
|
Definition at line 36 of file ParticleTrimmer.h. Referenced by RunTrimmer(). |
|
|
Definition at line 29 of file ParticleTrimmer.h. Referenced by ParticleTrimmer(), and trimPOT(). |
|
|
Definition at line 28 of file ParticleTrimmer.h. Referenced by ParticleTrimmer(), and trimPRecord(). |
|
|
Definition at line 31 of file ParticleTrimmer.h. Referenced by ParticleTrimmer(), and trimPOT(). |
1.3.9.1