FEDRA emulsion software from the OPERA Collaboration
tracks2edb.C File Reference
#include "EdbCluster.h"
#include "EdbFrame.h"
#include "EdbView.h"
#include "EdbSegment.h"
#include "EdbDataSet.h"
#include "TEventList.h"
#include "Riostream.h"
#include "stdlib.h"
#include "TCut.h"
#include "TH1F.h"
Include dependency graph for tracks2edb.C:

Functions

TEventList * GetCPListFromTracks (const char *fname, Int_t pid, const char *cutstr="1", Int_t *retpiece_id=0, Int_t *retpiece_piece=0)
 
int main (int argc, char *argv[])
 
Int_t tracks2edb (const char *datasetname, Int_t pieceID, const char *outfname="edb_from_cp.root", const char *options="", const char *cutstr_cp="1", const char *tracksfname="", const char *cutstr_tr="1")
 

Function Documentation

◆ GetCPListFromTracks()

TEventList * GetCPListFromTracks ( const char *  fname,
Int_t  pid,
const char *  cutstr = "1",
Int_t *  retpiece_id = 0,
Int_t *  retpiece_piece = 0 
)
31{
32 // OPEN TRACKS FILE
33 cout << " ... open the volume tracks file " << fname << endl;
34 TFile* trfile = new TFile(fname);
35 TTree* tracks = (TTree*) gDirectory->Get("tracks");
36 Int_t nseg=0;
37 EdbSegP *trk=0;
38 TClonesArray *seg = new TClonesArray("EdbSegP", 60);
39 tracks->SetBranchAddress("nseg", &nseg);
40 tracks->SetBranchAddress("t.", &trk);
41 tracks->SetBranchAddress("s", &seg);
42 cout << " ... number of volume tracks: " << tracks->GetEntries() << endl;
43
44 // SET THE TRACKS EVENTLIST
45 char str[128];
46 sprintf(str,"s.ePID == %d && %s",pid,cutstr);
47 TCut cut;
48 cut= str ;
49 tracks->Draw(">>trlst",cut);
50 TEventList *trlst = (TEventList*)gDirectory->GetList()->FindObject("trlst");
51 Int_t ntracks = (Int_t) trlst->GetN();
52 cout << " ... number of volume tracks in the piece "<<pid <<" : " <<ntracks;
53 if (cutstr[0]=='1') cout<<endl; else cout << " /\""<< cutstr <<"\"" << endl;
54
55 // CREATE THE EVENTLIST FOR THE COUPLES TREE
56 TEventList* cplst = new TEventList("cplst","cplst",ntracks);
57 EdbSegP *s1=0;
58 for(Int_t i=0; i<ntracks; i++) {
59 Int_t trID = trlst->GetEntry(i);
60 tracks->GetEntry(trID);
61 for(Int_t j=0 ; j<nseg; j++)
62 {
63 s1 = (EdbSegP*)(seg->At(j));
64 if (s1->PID() == pid) break;
65 }
66 Int_t cpID = s1->Vid(1);
67 // cout <<"i:"<<i<<" PID: " << s1->PID() <<" z: "<< s1->Z()<< " trID: "<< trID << " cpID:" << cpID << endl;
68 cplst->Enter(cpID);
69 }
70 Int_t piece_id = (int) s1->Vid(0)/1000 ;
71 Int_t piece_piece = s1->Vid(0)%(((int) s1->Vid(0)/1000)*1000) ;
72 cout << " ... plate id " << piece_id <<" "<< piece_piece <<" z : " << s1->Z() << endl;
73
74 if(retpiece_id) *retpiece_id = piece_id ;
75 if(retpiece_piece) *retpiece_piece = piece_piece ;
76 trfile->Close();
77 return cplst;
78}
Definition: EdbSegP.h:21
Float_t Z() const
Definition: EdbSegP.h:153
Int_t PID() const
Definition: EdbSegP.h:148
Int_t Vid(int i) const
Definition: EdbSegP.h:168
int pid[1000]
Definition: m2track.cpp:13
TCut cut
Definition: check_shower.C:6
TTree * tracks
Definition: check_tr.C:19
EdbSegP * s1
Definition: tlg2couples.C:29
const char * fname
Definition: mc2raw.cxx:41

◆ main()

int main ( int  argc,
char *  argv[] 
)
292{
293 char dataset[256];
294 Int_t piece=-1;
295 char outfilename[256]; sprintf(outfilename,"edb_from_tracks.root");
296 char tracksfilename[256]; sprintf(tracksfilename,"linked_tracks.root");
297 char cutstr_cp[256]; sprintf(cutstr_cp,"1");
298 char cutstr_tr[256]; sprintf(cutstr_tr,"1");
299 char options[256];
300 bool printusage=(argc<3)?true:false;
301 //bool writebck(false);
302 for (int i = 1; i < argc; i++) { // Skip argv[0] (program name)
303 if (!strcmp(argv[i], "-f")) { // Process optional arguments
304 if (i + 1 <= argc - 1) sprintf(outfilename,argv[++i]);
305 else printusage=true;
306 }
307 else if (!strcmp(argv[i], "-cutcp")) { // Process optional arguments
308 if (i + 1 <= argc - 1) sprintf(cutstr_cp,argv[++i]);
309 else printusage=true;
310 }
311 else if (!strcmp(argv[i], "-cuttr")) { // Process optional arguments
312 if (i + 1 <= argc - 1) sprintf(cutstr_tr,argv[++i]);
313 else printusage=true;
314 }
315 else if (!strcmp(argv[i], "-tr")) { // Process optional arguments
316 if (i + 1 <= argc - 1) { sprintf(tracksfilename,argv[++i]); strcat(options,"TR"); }
317 else printusage=true;
318 }
319 else if (!strcmp(argv[i], "-nocl")) strcat(options,"NOCL") ;
320 else if (!strcmp(argv[i], "-bck")) strcat(options,"BCK") ;
321 else { // Process non-optional arguments here
322 if( piece == -1 ) {
323 sprintf(dataset,"%s",argv[i++]) ;
324 piece=atoi(argv[i]);
325 }
326 }
327 }
328 if(printusage) {
329 cout << "\nusage: tracks2edb <data_set.def> <piece number> [options]" << endl;
330 cout << "\n Load the data_set and open the <piece number> raw data file (edb format)." << endl;
331 cout << " Then create a new edb raw data file only with the micro-tracks which belong to" << endl;
332 cout << " the couples. Optionally it is possible to cut the couples or to select" << endl;
333 cout << " couples which belongs to volume tracks (with/without cuts on the vol. tracks)." << endl;
334 cout << " options: -f filename = set output filename (def: edb_from_tracks.root)" << endl;
335 cout << " -nocl = don't add clusters" << endl;
336 cout << " -cutcp \"cutstr\" = cut the couples with \"cutstr\"" << endl;
337 cout << " example -cutcp \"eCHI2P>0.4*(.eW-12)\" " << endl;
338 cout << " -tr linked_tracks.root = only couples which belongs to vol. tracks" << endl;
339 cout << " -cuttr \"cutstr\" = cut the linked tracks with \"cutstr\" " << endl;
340 cout << " example -cuttr \"nseg>=3\" " << endl;
341 cout << " -bck create the complementary file" << endl;
342 return 0;
343 }
344 else tracks2edb(dataset, piece, outfilename, options, cutstr_cp,tracksfilename,cutstr_tr);
345}
Int_t tracks2edb(const char *datasetname, Int_t pieceID, const char *outfname="edb_from_cp.root", const char *options="", const char *cutstr_cp="1", const char *tracksfname="", const char *cutstr_tr="1")
Definition: tracks2edb.C:84

◆ tracks2edb()

Int_t tracks2edb ( const char *  datasetname,
Int_t  pieceID,
const char *  outfname = "edb_from_cp.root",
const char *  options = "",
const char *  cutstr_cp = "1",
const char *  tracksfname = "",
const char *  cutstr_tr = "1" 
)
91{
92 Bool_t addcl(true), usevoltracks(false), writebck(false);
93 // SCAN OPTIONS
94 if (strstr(options,"NOCL") ) addcl=false;
95 if (strstr(options,"TR") ) usevoltracks=true;
96 if (strstr(options,"BCK") ) writebck=true;
97
98 // OPEN THE DATASET
99 EdbDataSet dataset(datasetname);
100 Int_t nplates = dataset.N();
101 cout << "The dataset has " << nplates << " plates" << endl;
102
103 // OPEN COUPLES FILE
104 cout << "Open the plate n. " << pieceID << endl;
105 EdbDataPiece *piece = dataset.GetPiece(pieceID);
106 TTree *couples = piece->InitCouplesTree(piece->GetNameCP(), "READ");
107 if(piece->Nruns() != 1) { cout << "Raw data not found" << endl; return 0; }
108 Float_t piece_z = piece->GetLayer(0)->Z() ;
109 Int_t piece_id = piece->Plate() ;
110 Int_t piece_piece = atoi( piece->MakeName()+3 );
111 cout << " plate id "<<piece_id <<" " << piece_piece<<" z: " << piece_z << endl;
112 cout << " - Number of couples: " << couples->GetEntries() << endl;
113
114 EdbSegCouple *cp=0;
115 EdbSegP *s=0;
116 EdbSegP *s1=0;
117 EdbSegP *s2=0;
118 couples->SetBranchAddress("cp" ,&cp ); // not "cp." but "cp"
119 couples->SetBranchAddress("s." ,&s );
120 couples->SetBranchAddress("s1." ,&s1 );
121 couples->SetBranchAddress("s2." ,&s2 );
122 couples->Draw(">>y");
123
124 // GET THE COUPLES EVENTLIST FROM THE TRACKS
125 if(usevoltracks)
126 {
127 Int_t retpiece_id, retpiece_piece;
128 TEventList* cplist = GetCPListFromTracks(tracksfname, pieceID, cutstr_tr, &retpiece_id , &retpiece_piece ) ;
129 if (retpiece_id != piece_id || retpiece_piece != piece_piece )
130 {
131 cout << " ERROR: the piece ID or the piece number do not corresponds...." << endl;
132 return -1 ;
133 }
134 cout << " - Number of couples (in volume tracks): " << cplist->GetN() ;
135 if (cutstr_tr[0]=='1') cout<<endl; else cout << " /\""<< cutstr_tr <<"\"" << endl;
136 couples->SetEventList(cplist);
137 }
138
139 // Show the number of selected couples
140 TCut cut_cp;
141 cut_cp = cutstr_cp ;
142 Int_t selcp = couples->Draw(">>dum", cut_cp);
143 cout << " - Number of selected couples: " << selcp;
144 if (cutstr_cp[0]!='1') cout << " /\""<< cutstr_cp <<"\"";
145 if (usevoltracks) cout << " (belonging to volume tracks)";
146 if (cutstr_tr[0]=='1') cout << endl; else cout << " /\""<< cutstr_tr <<"\"" << endl;
147 // return -1;
148
149 //INVERT COUPLES
150 const EdbAffine2D *Aff = piece->GetLayer(0)->GetAffineXY();
151 EdbAffine2D *InvAff = (EdbAffine2D*) Aff->Clone();
152 InvAff->Invert();
153
154 // OPEN RAW DATA FILE AND CREATE A CONTAINER FOR ITS VIEWS
155 EdbRun* run1 = new EdbRun(piece->GetRunFile(0),"READ");
156 cout << run1->GetFile()->GetName() << endl;
157 cout << dataset.GetPiece(pieceID)->GetNameCP() << endl;
158 EdbView* v1=0;
159 v1=run1->GetView();
160 EdbViewHeader* vh1 = v1->GetHeader();
161
162 // OPEN OUTPUT DATA FILE AND CREATE A CONTAINER FOR ITS VIEWS
163 EdbRun* outrun = new EdbRun(outfname,"RECREATE");
164 EdbView* outv=0;
165 outv=outrun->GetView();
166 EdbViewHeader* outvh = outv->GetHeader();
167
168 // SET THE RUN HEADER
169 EdbRunHeader* rh1 = run1->GetHeader() ;
170 EdbRunHeader* outrh = outrun->GetHeader() ;
171 *outrh = *rh1 ;
172
173 // START FILLING VIEWS...
174 cout<<"Add clusters "; if(addcl) cout<<"enabled\n"; else cout<<"disabled\n"; cout <<endl;
175 printf("Start Filling... ... %3d%%", 0) ;
176 Int_t nviews= run1->GetEntries();
177 char str[128];
178 TCut cut;
179 EdbSegment* rawseg;
180 EdbSegP* segp;
181
182 Int_t totsegments=0;
183 //for(Int_t i=0; i<1; i++)
184 for(Int_t i=0; i<nviews; i++)
185 {
186 if(i%100==0) printf("\b\b\b\b%3d%%",(int)((double)i/double(nviews)*100.));
187
188 v1->Clear() ;
189 outv->Clear() ;
190 v1 = run1->GetEntry(i,1,addcl,1,0,1);
191 Int_t side= v1->GetNframesTop()? 1 :0 ;
192
193 //SET THE EVENT LIST (GET THE COUPLES WHICH HAVE AT LEAST ONE SEGMENT IN THE VIEW)
194 sprintf(str,"s1.eVid[0]==%d || s2.eVid[0]==%d",i,i);
195 cut= str ;
196 //couples->Draw(">>lst",cut_cp && cut && "eN1==1 && eN2==1");
197 couples->Draw(">>lst",cut_cp && cut );
198 TEventList *lst = (TEventList*)gDirectory->GetList()->FindObject("lst");
199
200 Long_t nlinked = lst->GetN(); //cout<<"nlinked: "<<nlinked<<endl;
201 Long_t ntotal = v1->Nsegments(); //cout<<"ntotal : "<<ntotal<<endl;
202 Long_t nselected;
203
204 // CREATE THE LIST OF LINKED SEGMENTS
205 TIndexCell* listselected = new TIndexCell();;
206 TIndexCell* listlinked = new TIndexCell();
207 Long_t segID;
208 for(int j=0;j<nlinked;j++) {
209 couples->GetEntry(lst->GetEntry(j));
210 segp = side? s1: s2 ;
211 segID = segp->Vid(1); //cout <<segID<< " " ;
212 //listlinked->Add(segID);
213 listlinked->FindAdd(segID); //if FindAdd is used nlinked must be re-evaluated (*)
214 }
215 if(listlinked) nlinked = listlinked->GetEntries(); // (*) nlinked is re-eveluated to remove the duplicated segment
216 if(listlinked) listlinked->Sort(); //cout<<"view: "<<i<<" ";for(int l=0;l<nlinked;l++)cout <<" "<<listlinked->At(l)->Value();cout<<endl;
217
218 // CREATE THE LIST OF SELECTED SEGMENTS
219 if(writebck) {
220 // COMPLEMENTARY LIST
221 Int_t iLink=0;
222 for(Int_t j=0;j<ntotal;j++) {
223 // in the next line, nlinked must be evaluated first otherwise if nlinked is 0 the program crashes
224 if ( nlinked && j == listlinked->At(iLink)->Value() ) {
225 if(iLink < nlinked-1) iLink++;
226 continue;
227 } else {
228 segID = (Long_t) j ; //cout <<segID[0]<< " " ;
229 listselected->Add(segID);
230 }
231 }
232 nselected = listselected->GetEntries();
233 } else {
234 listselected = listlinked;
235 nselected = nlinked ;
236 }
237 //cout <<"nselected: "<<nselected<<endl;
238 //for(int l=0;l<nselected;l++)cout <<" "<<listselected->At(l)->Value();cout<<endl;
239 totsegments += nselected;
240
241 // copy view header
242 EdbAffine2D const * aff = vh1->GetAffine();
243 outvh->SetAffine(aff->A11(),aff->A12(),aff->A21(),aff->A22(),aff->B1(),aff->B2()) ;
244 outvh->SetAreaID(vh1->GetAreaID());
245 outvh->SetCoordXY(vh1->GetXview(), vh1->GetYview());
246 outvh->SetCoordZ(vh1->GetZ1(),vh1->GetZ2(), vh1->GetZ3(),vh1->GetZ4());
247 outvh->SetNframes(vh1->GetNframesTop(),vh1->GetNframesBot());
248 outvh->SetNsegments(nselected);
249 outvh->SetViewID(vh1->GetViewID());
250
251 //copy view frames
252 for(Int_t f=0; f< v1->GetNframes(); f++ ) {
253 EdbFrame* frame = (EdbFrame *) (v1->GetFrames())->At(f) ;
254 outv->AddFrame(frame->GetID(),frame->GetZ(),frame->GetNcl());
255 }
256
257 if (addcl) v1->AttachClustersToSegments() ;
258 // ADD SEGMENTS
259 for(Int_t j=0; j<nselected; j++) {
260 //Int_t segID=lst->GetEntry(j);
261 //couples->GetEntry(segID);
262 //segp = side? s1: s2 ;
263 rawseg = v1->GetSegment(listselected->At(j)->Value()); //cout <<listselected->At(j)->Value()<<"\t";
264 //rawseg = v1->GetSegment(segp->Vid(1)); cout <<segp->Vid(1)<<" "<<rawseg<<endl;
265 outv->AddSegment(rawseg);
266 if (addcl) {
267 EdbCluster *cl=0;
268 TObjArray *clusters = rawseg->GetElements();
269 if(!clusters) continue;
270 int ncl = clusters->GetLast()+1;
271 for(Int_t k=0; k<ncl; k++ ) {
272 cl = (EdbCluster*)clusters->At(k);
273 outv->AddCluster(cl) ;
274 }
275 }
276 }
277 outrun->AddView(outv);
278 }
279 printf("\b\b\b\b%3d%%\n",100);
280 cout << " - Number of selected segments: " << totsegments <<endl <<endl;
281 // outrun->Print();
282 outrun->Close();
283 run1->Close();
284 return 0;
285}
FILE * f
Definition: RecDispMC.C:150
Definition: EdbAffine.h:17
Float_t B2() const
Definition: EdbAffine.h:48
void Invert()
Definition: EdbAffine.cxx:103
Float_t A22() const
Definition: EdbAffine.h:46
Float_t A21() const
Definition: EdbAffine.h:45
Float_t A12() const
Definition: EdbAffine.h:44
Float_t B1() const
Definition: EdbAffine.h:47
Float_t A11() const
Definition: EdbAffine.h:43
Definition: EdbCluster.h:19
Edb raw data unit (scanned plate) associated with run file.
Definition: EdbDataSet.h:26
const char * GetRunFile(int i) const
Definition: EdbDataSet.cxx:183
EdbLayer * GetLayer(int id)
Definition: EdbDataSet.h:87
int InitCouplesTree(const char *mode="READ")
Definition: EdbDataSet.cxx:1239
int Nruns() const
Definition: EdbDataSet.h:84
const char * GetNameCP() const
Definition: EdbDataSet.h:76
int Plate() const
Definition: EdbDataSet.h:66
const char * MakeName()
Definition: EdbDataSet.cxx:190
OPERA emulsion data set.
Definition: EdbDataSet.h:144
Definition: EdbFrame.h:20
float GetZ() const
Definition: EdbFrame.h:42
int GetNcl() const
Definition: EdbFrame.h:43
int GetID() const
Definition: EdbFrame.h:41
EdbAffine2D * GetAffineXY()
Definition: EdbLayer.h:119
float Z() const
Definition: EdbLayer.h:77
Definition: EdbRunHeader.h:95
Definition: EdbRun.h:75
void Close()
Definition: EdbRun.cxx:439
EdbView * GetView() const
Definition: EdbRun.h:110
int GetEntries() const
Definition: EdbRun.h:136
TFile * GetFile()
Definition: EdbRun.h:149
EdbRunHeader * GetHeader() const
Definition: EdbRun.h:138
EdbView * GetEntry(int entry, int ih=1, int icl=0, int iseg=1, int itr=0, int ifr=0)
Definition: EdbRun.cxx:462
void AddView()
Definition: EdbRun.cxx:305
Definition: EdbSegCouple.h:17
segment of the track
Definition: EdbSegment.h:63
TObjArray * GetElements() const
Definition: EdbSegment.h:117
view identification
Definition: EdbView.h:26
Float_t GetXview() const
Definition: EdbView.h:93
void SetCoordZ(float z1, float z2, float z3, float z4)
Definition: EdbView.h:102
Float_t GetYview() const
Definition: EdbView.h:94
Int_t GetNframesTop() const
Definition: EdbView.h:120
void SetNsegments(int nseg)
Definition: EdbView.h:86
void SetAreaID(int id)
Definition: EdbView.h:100
Float_t GetZ4() const
Definition: EdbView.h:113
void SetViewID(int id)
Definition: EdbView.h:99
EdbAffine2D const * GetAffine() const
Definition: EdbView.h:72
Int_t GetAreaID() const
Definition: EdbView.h:91
Int_t GetNframesBot() const
Definition: EdbView.h:121
void SetNframes(int top, int bot)
Definition: EdbView.h:104
Float_t GetZ2() const
Definition: EdbView.h:111
Float_t GetZ3() const
Definition: EdbView.h:112
void SetAffine(float a11, float a12, float a21, float a22, float b1, float b2)
Definition: EdbView.h:67
Int_t GetViewID() const
Definition: EdbView.h:90
void SetCoordXY(float x, float y)
Definition: EdbView.h:101
Float_t GetZ1() const
Definition: EdbView.h:110
Base scanning data object: entry into Run tree.
Definition: EdbView.h:134
EdbViewHeader * GetHeader() const
Definition: EdbView.h:163
EdbSegment * GetSegment(int i) const
Definition: EdbView.h:219
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
Int_t GetNframesTop() const
Definition: EdbView.h:207
int AttachClustersToSegments()
Definition: EdbView.cxx:360
Int_t Nsegments() const
Definition: EdbView.h:216
Int_t GetNframes() const
Definition: EdbView.h:206
EdbCluster * AddCluster(EdbCluster *c)
Definition: EdbView.h:225
void AddFrame(int id, float z, int ncl=0, int npix=0)
Definition: EdbView.cxx:268
TClonesArray * GetFrames() const
Definition: EdbView.h:167
void Clear()
Definition: EdbView.cxx:79
sort collection with attributes
Definition: TIndexCell.h:19
Long_t Value() const
Definition: TIndexCell.h:79
Int_t GetEntries() const
Definition: TIndexCell.h:82
TIndexCell const * At(Int_t narg, Int_t vind[]) const
Definition: TIndexCell.cpp:519
void Sort(Int_t upto=kMaxInt)
Definition: TIndexCell.cpp:539
TIndexCell * FindAdd(Long_t p1)
Definition: TIndexCell.cpp:575
Int_t Add(Int_t narg, Long_t varg[])
Definition: TIndexCell.cpp:602
TTree * couples
Definition: check_cp.C:50
s
Definition: check_shower.C:55
EdbSegP * s2
Definition: tlg2couples.C:30
EdbSegCouple * cp
Definition: tlg2couples.C:28
TEventList * GetCPListFromTracks(const char *fname, Int_t pid, const char *cutstr="1", Int_t *retpiece_id=0, Int_t *retpiece_piece=0)
Definition: tracks2edb.C:30