FEDRA emulsion software from the OPERA Collaboration
emtraceback.cpp File Reference
#include <assert.h>
#include <string.h>
#include <iostream>
#include <TRint.h>
#include <TEnv.h>
#include "EdbLog.h"
#include "EdbScanProc.h"
#include "EdbCouplesTree.h"
Include dependency graph for emtraceback.cpp:

Functions

void DoTraceBack (EdbID idset, TEnv &cenv, EdbID *idnew=0)
 
EdbID GetCPID (const EdbPattern &p)
 
void GroupViews (EdbID &cpid, const EdbPattern &p, const EdbPattern &pp1, const EdbPattern &pp2, EdbCell1 &cv1, EdbCell1 &cv2)
 
void GroupViews (EdbPattern &p, EdbCell1 &c)
 
int main (int argc, char *argv[])
 
void print_help_message ()
 
void set_default (TEnv &cenv)
 
void WriteRaw (EdbRunAccess &run, EdbRun &runout, EdbCell1 &cv, int rs)
 

Variables

EdbScanSetset = 0
 
EdbScanProc sproc
 

Function Documentation

◆ DoTraceBack()

void DoTraceBack ( EdbID  idset,
TEnv &  cenv,
EdbID idnew = 0 
)
99 {
100  int rs = cenv.GetValue("emtraceback.RS" , 0);
101  const char *cut = cenv.GetValue("emtraceback.tracks_read_cut" , "1");
102 
103  set = sproc.ReadScanSet(idset); assert(set);
104  EdbPVRec ali;
106 
107  int npat = ali.Npatterns();
108  for(int i=0; i<npat; i++)
109  {
110  EdbPattern *p = ali.GetPattern(i);
111  EdbID cpID = GetCPID(*p);
112 
113  TString cpfile;
114  sproc.MakeFileName(cpfile, cpID,"cp.root");
115  EdbCouplesTree cptree;
116  cptree.InitCouplesTree("couples",cpfile.Data());
117  EdbPattern pp,pp1,pp2;
118  cptree.GetCPData( &pp,&pp1,&pp2 );
119 
120  EdbCell1 cviews1; cviews1.InitCell(200, 50000, 0, 50000 );
121  EdbCell1 cviews2; cviews2.InitCell(200, 50000, 0, 50000 );
122  GroupViews( cpID,*p,pp1, pp2, cviews1, cviews2 );
123 
126  if(id_new) {
127  EdbID idn=(*id_new); idn.ePlate=cpID.ePlate;
128  sproc.MakeFileName(cpfile, idn,"raw.root");
129  } else {
130  sproc.MakeFileName(cpfile, cpID,"tr.raw.root");
131  }
132  EdbRun runout( cpfile.Data(),"RECREATE" );
133 
134  WriteRaw( run, runout, cviews1, rs );
135  WriteRaw( run, runout, cviews2, rs );
136  runout.Close();
137  }
138 
139 }
Int_t npat
Definition: Xi2HatStartScript.C:33
EdbPVRec * ali
Definition: align.C:1
TCut cut
Definition: check_shower.C:6
Definition: EdbCell1.h:117
int InitCell(int maxpercell, int n, float min, float max)
Definition: EdbCell1.cpp:503
Definition: EdbCouplesTree.h:17
bool InitCouplesTree(const char *name="couples", const char *fname=0, Option_t *mode="READ")
Definition: EdbCouplesTree.cxx:87
int GetCPData(EdbPattern *pat, EdbPattern *p1=0, EdbPattern *p2=0, TIndex2 *trseg=0)
Definition: EdbCouplesTree.cxx:325
Definition: EdbID.h:7
Int_t ePlate
Definition: EdbID.h:11
Definition: EdbPVRec.h:148
Definition: EdbPattern.h:280
Int_t Npatterns() const
Definition: EdbPattern.h:380
EdbPattern * GetPattern(int id) const
Definition: EdbPattern.cxx:1887
Definition: EdbRunAccess.h:22
Definition: EdbRun.h:74
void MakeFileName(TString &s, int id[4], const char *suffix, bool inplate=true)
Definition: EdbScanProc.cxx:1885
int ReadTracksTree(EdbID id, EdbPVRec &ali, TCut cut="1")
Definition: EdbScanProc.cxx:644
bool InitRunAccessNew(EdbRunAccess &ra, EdbID id, EdbPlateP &plate, bool do_update=false)
Definition: EdbScanProc.cxx:3182
EdbScanSet * ReadScanSet(EdbID id)
Definition: EdbScanProc.cxx:1521
TEnv cenv("emrec")
EdbID idset
Definition: emrec.cpp:35
void GroupViews(EdbPattern &p, EdbCell1 &c)
EdbID GetCPID(const EdbPattern &p)
Definition: emtraceback.cpp:142
EdbScanProc sproc
Definition: emtraceback.cpp:13
void WriteRaw(EdbRunAccess &run, EdbRun &runout, EdbCell1 &cv, int rs)
Definition: emtraceback.cpp:183
EdbScanSet * set
Definition: emtraceback.cpp:14
EdbRun * run
Definition: check_raw.C:38
p
Definition: testBGReduction_AllMethods.C:8

◆ GetCPID()

EdbID GetCPID ( const EdbPattern p)
143 {
144  int nseg = p.N();
145  EdbID id;
146  int cnt=0;
147  for(int isg=0; isg<nseg; isg++)
148  {
149  if( id != p.GetSegment(isg)->ScanID() )
150  {
151  id = p.GetSegment(isg)->ScanID();
152  cnt=1;
153  } else {
154  cnt++;
155  }
156  }
157  Log(3,"GetCPID","cnt = %d for %s",cnt, id.AsString() );
158  return id;
159 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
UInt_t id
Definition: tlg2pattern.C:118

◆ GroupViews() [1/2]

void GroupViews ( EdbID cpid,
const EdbPattern p,
const EdbPattern pp1,
const EdbPattern pp2,
EdbCell1 cv1,
EdbCell1 cv2 
)
163 {
164  int nseg = p.N();
165  Log(3,"GroupViews","%d segments to read ",nseg );
166 
167  //c1.Print();
168  for(int isg=0; isg<nseg; isg++)
169  {
170  int entr = p.GetSegment(isg)->ID();
171  if( !c1.AddObject( pp1.GetSegment(entr)->Vid(0), pp1.GetSegment(entr)) )
172  Log(1,"GroupViews","ERROR: can't add segment to c1 %d",
173  pp1.GetSegment(entr)->Vid(0) );
174  if( !c2.AddObject( pp2.GetSegment(entr)->Vid(0), pp2.GetSegment(entr)) )
175  Log(1,"GroupViews","ERROR: can't add segment to c2 %d",
176  pp2.GetSegment(entr)->Vid(0) );
177  }
178 
179  Log(2,"GroupViews","%d segments read from tree with %d entries",nseg, pp1.N() );
180 }
Int_t Vid(int i) const
Definition: EdbSegP.h:165
Int_t N() const
Definition: EdbPattern.h:89
EdbSegP * GetSegment(int i) const
Definition: EdbPattern.h:66
TCanvas * c1
Definition: energy.C:13
TCanvas * c2
Definition: energy.C:26

◆ GroupViews() [2/2]

void GroupViews ( EdbPattern p,
EdbCell1 c 
)

◆ main()

int main ( int  argc,
char *  argv[] 
)
49 {
50  if (argc < 2) { print_help_message(); return 0; }
51 
52  TEnv cenv("emtraceback");
54  gEDBDEBUGLEVEL = cenv.GetValue("emtraceback.EdbDebugLevel" , 1);
55  const char *env = cenv.GetValue("emtraceback.env" , "trfind.rootrc");
56  const char *outdir = cenv.GetValue("emtraceback.outdir" , "..");
57 
58  bool do_set = false;
59  EdbID *id_new=0;
60  EdbID idset,idnew;
61 
62  for(int i=1; i<argc; i++ ) {
63  char *key = argv[i];
64 
65  if (!strncmp(key,"-set=",5))
66  {
67  if(strlen(key)>5) if(idset.Set(key+5)) do_set=true;
68  }
69  else if (!strncmp(key,"-newset=",8))
70  {
71  if(strlen(key)>8) if(idnew.Set(key+8)) id_new = &idnew;
72  }
73  else if(!strncmp(key,"-v=",3))
74  {
75  if(strlen(key)>3) gEDBDEBUGLEVEL = atoi(key+3);
76  }
77  }
78 
79  if(!(do_set)) { print_help_message(); return 0; }
80 
81  cenv.SetValue("emtraceback.env" , env);
82  cenv.ReadFile( cenv.GetValue("emtraceback.env" , "traceback.rootrc") ,kEnvLocal);
83  cenv.SetValue("emtraceback.outdir" , outdir);
84  sproc.eProcDirClient = cenv.GetValue("emtraceback.outdir","..");
85  cenv.WriteFile("traceback.save.rootrc");
86 
87 
88  printf("\n----------------------------------------------------------------------------\n");
89  printf("Copy raw segments of reconstructed tracks from %s to %s\n" ,idset.AsString(), idnew.AsString());
90  printf("----------------------------------------------------------------------------\n\n");
91 
92  DoTraceBack( idset, cenv, id_new );
93 
94  return 0;
95 }
char * AsString() const
Definition: EdbID.cxx:24
bool Set(const char *id_string)
Definition: EdbID.cxx:17
TString eProcDirClient
Definition: EdbScanProc.h:14
bool do_set
Definition: emrec.cpp:36
const char * outdir
Definition: emrec.cpp:37
void set_default(TEnv &cenv)
Definition: emtraceback.cpp:37
void print_help_message()
Definition: emtraceback.cpp:22
void DoTraceBack(EdbID idset, TEnv &cenv, EdbID *idnew=0)
Definition: emtraceback.cpp:98
gEDBDEBUGLEVEL
Definition: energy.C:7

◆ print_help_message()

void print_help_message ( )
23 {
24  cout<< "\n For a given dataset produce *.tr.raw.root files in plate \n";
25  cout<< " directories conserving volume tracks raw segments only\n";
26  cout<< " If -newset option is defined - save data into newid.raw.root files\n";
27  cout<< "\nUsage: \n\t emtrfind -set=idset [-newset=idnew -v=DEBUG] \n";
28  cout<< "\nExample: \n";
29  cout<< "\t emtraceback -set=4554.0.1.1 -v=2\n";
30  cout<< "\n If the data location directory if not explicitly defined\n";
31  cout<< " the current directory will be assumed to be the brick directory \n";
32  cout<< "\n If the parameters file (traceback.rootrc) is not presented - the default \n";
33  cout<< " parameters will be used. After the execution them are saved into traceback.save.rootrc file\n";
34  cout<<endl;
35 }

◆ set_default()

void set_default ( TEnv &  cenv)
38 {
39  // default parameters for the new alignment
40  cenv.SetValue("emtraceback.tracks_read_cut" , "1");
41  cenv.SetValue("emtraceback.RS" , 0);
42  cenv.SetValue("emtraceback.outdir" , ".." );
43  cenv.SetValue("emtraceback.env" , "traceback.rootrc");
44  cenv.SetValue("emtraceback.EdbDebugLevel" , 1 );
45 }

◆ WriteRaw()

void WriteRaw ( EdbRunAccess run,
EdbRun runout,
EdbCell1 cv,
int  rs 
)
184 {
185  int nv = cv.Ncell();
186  for( int iv=0; iv<nv; iv++ ) {
187  int nsv=cv.Bin(iv);
188  if(!nsv) continue;
189 
190  EdbView *vin = run.GetRun()->GetEntry(iv);
191  EdbView *vout = runout.GetView();
192  vout->GetHeader()->Copy( vin->GetHeader() );
193 
194  for( int is=0; is<nsv; is++ ) {
195  EdbSegP *sp = (EdbSegP *)(cv.GetObject(iv,is));
196 
197  EdbSegment *sraw = vin->GetSegment(sp->Vid(1));
198  if(rs>0) run.ApplyCorrections( *vin, *sraw, rs );
199 
200  if(gEDBDEBUGLEVEL>3) {
201  printf("\n");
202  sp->PrintNice();
203  sraw->Print();
204  }
205 
206  vout->AddSegment(sraw);
207 
208  EdbTrack t( sp->X(), sp->Y(), sp->Z(), sp->TX(), sp->TY(),sp->DZ(), sp->ID() );
209  vout->AddTrack(&t); // save sp for crosscheck. Note that the last emlink should be done with all corrections off for consistency
210 
211  }
212  runout.AddView(vout);
213  }
214 }
TCanvas * cv
Definition: RecDispMC_Profiles.C:63
TTree * t
Definition: check_shower.C:4
EdbView * GetEntry(int entry, int ih=1, int icl=0, int iseg=1, int itr=0, int ifr=0)
Definition: EdbRun.cxx:489
void AddView()
Definition: EdbRun.cxx:332
EdbView * GetView() const
Definition: EdbRun.h:109
Definition: EdbSegP.h:18
Float_t DZ() const
Definition: EdbSegP.h:151
Float_t TX() const
Definition: EdbSegP.h:172
Int_t ID() const
Definition: EdbSegP.h:144
Float_t X() const
Definition: EdbSegP.h:170
Float_t Z() const
Definition: EdbSegP.h:150
Float_t Y() const
Definition: EdbSegP.h:171
void PrintNice() const
Definition: EdbSegP.cxx:418
Float_t TY() const
Definition: EdbSegP.h:173
Definition: EdbSegment.h:61
void Print(Option_t *opt=0) const
Definition: EdbSegment.cxx:139
Definition: EdbSegment.h:125
void Copy(EdbViewHeader *h)
Definition: EdbView.h:65
Definition: EdbView.h:134
EdbViewHeader * GetHeader() const
Definition: EdbView.h:163
void AddTrack(EdbTrack *t)
Definition: EdbView.cxx:261
EdbSegment * AddSegment(float x, float y, float z, float tx, float ty, float dz=0, int side=0, int puls=0, int id=-1)
Definition: EdbView.h:231
EdbSegment * GetSegment(int i) const
Definition: EdbView.h:219

Variable Documentation

◆ set

EdbScanSet* set = 0

◆ sproc

EdbScanProc sproc