/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by pam-fi, Thu Jan 18 11:56:12 2007 UTC revision 1.20 by pam-fi, Fri Feb 16 15:00:35 2007 UTC
# Line 100  PamLevel2::PamLevel2(){ Line 100  PamLevel2::PamLevel2(){
100  //     nd_obj    = NDLevel2::GetNDLevel2();  //     nd_obj    = NDLevel2::GetNDLevel2();
101  //     ac_obj    = AcLevel2::GetAcLevel2();  //     ac_obj    = AcLevel2::GetAcLevel2();
102  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();  //     orb_obj   = OrbitalInfo::GetOrbitalInfo();
103        
104        h0_obj    = 0;
105        trk0_obj  = 0;
106    
107      trk2_obj  = 0;      trk2_obj  = 0;
108      trk1_obj  = 0;      trk1_obj  = 0;
109      trkh_obj  = 0;      trkh_obj  = 0;
# Line 118  PamLevel2::PamLevel2(){ Line 122  PamLevel2::PamLevel2(){
122      runfirstentry = 0ULL;      runfirstentry = 0ULL;
123      runlastentry = 0ULL;      runlastentry = 0ULL;
124    
125      for(Int_t i=0; i<8; i++ )tree_clone[i]=NULL;      l0_file = NULL;
126        l0_tree = NULL;
127        iroot   = -1;
128        dbc     = 0;
129        
130        irun = -1;
131        run_tree = NULL;
132        run_tree_clone = NULL;
133        sel_tree = NULL;
134        sel_tree_clone = NULL;
135        
136        irunentry = -1;
137        pam_tree = NULL;
138        for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL;
139    
140        host = "mysql://localhost/pamelaprod";
141        user = "anonymous";
142        psw = "";
143        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
144        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
145        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
146        if ( !pamdbhost ) pamdbhost = "";
147        if ( !pamdbuser ) pamdbuser = "";
148        if ( !pamdbpsw ) pamdbpsw = "";
149        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
150        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
151        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
152    
153        
154    
155  //    sorted_tracks = 0;//new TRefArray();  //    sorted_tracks = 0;//new TRefArray();
156            
157        CAL0 = false;
158      CAL1 = true;      CAL1 = true;
159      CAL2 = true;      CAL2 = true;
160      TRK2 = true;      TRK2 = true;
161      TRK1 = false;      TRK1 = false;
162      TRKh = false;      TRKh = false;
163      TRG = true;      TRKh = false;
164      TOF = true;      TRG  = true;
165      S4  = true;      TOF  = true;
166      ND  = true;      TOF0 = false;
167      AC  = true;      S4   = true;
168      ORB = true;      ND   = true;
169        AC   = true;
170        ORB  = true;
171            
172      RUN = true;      RUN  = true;
173    
174        SELLI = -1;
175    
176      tsorted=0;      tsorted=0;
177      timage=0;      timage=0;
# Line 149  void PamLevel2::Delete(){ Line 186  void PamLevel2::Delete(){
186      if(soft_obj)delete soft_obj; //Emiliano      if(soft_obj)delete soft_obj; //Emiliano
187    
188  //    cout << "void PamLevel2::Clear()"<<endl;  //    cout << "void PamLevel2::Clear()"<<endl;
189        if(h0_obj)   delete h0_obj;
190        if(trk0_obj) delete trk0_obj;      
191      if(trk1_obj) delete trk1_obj;            if(trk1_obj) delete trk1_obj;      
192      if(trk2_obj) delete trk2_obj;      if(trk2_obj) delete trk2_obj;
193      if(trkh_obj) delete trkh_obj;      if(trkh_obj) delete trkh_obj;
# Line 169  void PamLevel2::Delete(){ Line 208  void PamLevel2::Delete(){
208          timage->Delete();          timage->Delete();
209          delete timage;          delete timage;
210      }      }
211    
212        if(dbc){
213            dbc->Close();
214            delete dbc;
215        }
216        
217        if(l0_file)l0_file->Close();
218        if(pam_tree)pam_tree->Delete();;
219        if(run_tree)run_tree->Delete();;
220        if(sel_tree)sel_tree->Delete();;
221        for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();;
222        if(run_tree_clone)run_tree_clone->Delete();;
223        if(sel_tree_clone)sel_tree_clone->Delete();;
224        
225    
226  };  };
227    
228  /**  /**
# Line 186  void PamLevel2::Clear(){ Line 240  void PamLevel2::Clear(){
240  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead  //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead
241  //    if(soft_obj) soft_obj->Clear();  //    if(soft_obj) soft_obj->Clear();
242    
243        if(h0_obj)   h0_obj->Clear();      
244        if(trk0_obj) trk0_obj->Clear();    
245      if(trk1_obj) trk1_obj->Clear();          if(trk1_obj) trk1_obj->Clear();    
246      if(trk2_obj) trk2_obj->Clear();      if(trk2_obj) trk2_obj->Clear();
247      if(trkh_obj) trkh_obj->Clear();      if(trkh_obj) trkh_obj->Clear();
# Line 775  TTree *PamLevel2::GetPamTree(TFile *f, T Line 831  TTree *PamLevel2::GetPamTree(TFile *f, T
831    
832  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);  //     if( !detlist.IsNull() ) SetWhichTrees(detlist);
833  //     else                    GetWhichTrees(f);  //     else                    GetWhichTrees(f);
834        
835        cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl;
836    
837      SetWhichTrees(detlist);      SetWhichTrees(detlist);
838    
839      TTree *Trout =0;      TTree *Trout =0;
# Line 782  TTree *PamLevel2::GetPamTree(TFile *f, T Line 841  TTree *PamLevel2::GetPamTree(TFile *f, T
841      TString fname = f->GetName();      TString fname = f->GetName();
842      if(!CheckLevel2File(fname))return NULL;      if(!CheckLevel2File(fname))return NULL;
843    
844      UInt_t *found=0;      //    UInt_t *found=0;    
845    
846      cout<< "GetPamTree(TFile*,TString): detector list --> ";      cout<< "GetPamTree(TFile*,TString): detector list --> ";
847      if(TRK1)cout<<"TRK1 ";      if(TRK1)cout<<"TRK1 ";
# Line 797  TTree *PamLevel2::GetPamTree(TFile *f, T Line 856  TTree *PamLevel2::GetPamTree(TFile *f, T
856      if(S4)cout<<"S4 ";      if(S4)cout<<"S4 ";
857      if(ORB)cout<<"ORB ";      if(ORB)cout<<"ORB ";
858      cout << endl;      cout << endl;
859        if(SELLI)cout<<">>> Found selection-list <<<"<<endl;
860    
861      f->cd();      f->cd();
862    
# Line 804  TTree *PamLevel2::GetPamTree(TFile *f, T Line 864  TTree *PamLevel2::GetPamTree(TFile *f, T
864      TTree *T = (TTree*)f->Get("Tracker");      TTree *T = (TTree*)f->Get("Tracker");
865      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
866          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
867          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
868          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
869          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
870          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
871          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
872          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
873          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
874          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
875          if(!Trout)Trout=T;          if(!Trout)Trout=T;
876          else Trout->AddFriend(T);          else Trout->AddFriend(T);
# Line 821  TTree *PamLevel2::GetPamTree(TFile *f, T Line 881  TTree *PamLevel2::GetPamTree(TFile *f, T
881      TTree *C = (TTree*)f->Get("Calorimeter");      TTree *C = (TTree*)f->Get("Calorimeter");
882      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
883          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
884          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
885          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
886          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
887          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
888          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
889          if(!Trout)Trout=C;          if(!Trout)Trout=C;
890          else Trout->AddFriend(C);          else Trout->AddFriend(C);
# Line 892  TTree *PamLevel2::GetPamTree(TFile *f, T Line 952  TTree *PamLevel2::GetPamTree(TFile *f, T
952      }else{      }else{
953          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
954      };      };
955    
956        TTree *L = (TTree*)f->Get("SelectionList");
957        if(L && SELLI==1) {
958    //      L->SetBranchAddress("RunEntry",&irun);
959    //      cout << "SelectionList: set branch address RunEntry"<<endl;
960    //      L->SetBranchAddress("EventEntry",&irunentry);
961    //      cout << "SelectionList: set branch address EventEntry"<<endl;
962    //      if(!Trout)Trout=O;
963    //      else Trout->AddFriend("SelectionList");
964            cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemente!!!!"<<endl;
965            sel_tree = 0;
966        }else{
967            cout << "SelectionList  : missing tree"<<endl;
968        };
969            
970      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;      cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
971            
# Line 1051  TChain *PamLevel2::GetPamTree(TList *fl, Line 1125  TChain *PamLevel2::GetPamTree(TList *fl,
1125      TChain *N = 0;      TChain *N = 0;
1126      TChain *A = 0;      TChain *A = 0;
1127      TChain *B = 0;      TChain *B = 0;
1128    
1129        TChain *L = 0;
1130            
1131      if(TRK2||TRK1||TRKh) T = new TChain("Tracker");          if(TRK2||TRK1||TRKh) T = new TChain("Tracker");    
1132      if(CAL2||CAL1)       C = new TChain("Calorimeter");      if(CAL2||CAL1)       C = new TChain("Calorimeter");
# Line 1060  TChain *PamLevel2::GetPamTree(TList *fl, Line 1136  TChain *PamLevel2::GetPamTree(TList *fl,
1136      if(ND)               N = new TChain("NeutronD");      if(ND)               N = new TChain("NeutronD");
1137      if(AC)               A = new TChain("Anticounter");      if(AC)               A = new TChain("Anticounter");
1138      if(ORB)              B = new TChain("OrbitalInfo");      if(ORB)              B = new TChain("OrbitalInfo");
1139    
1140         L = new TChain("SelectionList");
1141            
1142      // loop over files and create chains              // loop over files and create chains        
1143      TIter next(fl);      TIter next(fl);
# Line 1076  TChain *PamLevel2::GetPamTree(TList *fl, Line 1154  TChain *PamLevel2::GetPamTree(TList *fl,
1154              if(ND)               N->Add(name);              if(ND)               N->Add(name);
1155              if(AC)               A->Add(name);              if(AC)               A->Add(name);
1156              if(ORB)              B->Add(name);              if(ORB)              B->Add(name);
1157                if(SELLI==1)         L->Add(name);
1158          };          };
1159      }      }
1160            
1161      cout << "done chain \n";      cout << "done chain \n";
1162    
1163      UInt_t *found=0;  //    UInt_t *found=0;
1164  // Tracker  // Tracker
1165      if(T && (TRK2||TRK1||TRKh)) {      if(T && (TRK2||TRK1||TRKh)) {
1166          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));          if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2"));
1167          else    T->SetBranchStatus("TrkLevel2",0,found);  //      else    T->SetBranchStatus("TrkLevel2",0,found);
1168          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;          if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl;
1169          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));          if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1"));
1170          else    T->SetBranchStatus("TrkLevel1",0,found);  //      else    T->SetBranchStatus("TrkLevel1",0,found);
1171          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;          if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl;
1172          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));          if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough"));
1173          else    T->SetBranchStatus("TrkHough",0,found);  //      else    T->SetBranchStatus("TrkHough",0,found);
1174          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;          if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl;
1175          if(!Trout)Trout=T;          if(!Trout)Trout=T;
1176          else Trout->AddFriend("Tracker");          else Trout->AddFriend("Tracker");
# Line 1101  TChain *PamLevel2::GetPamTree(TList *fl, Line 1180  TChain *PamLevel2::GetPamTree(TList *fl,
1180      // Calorimeter      // Calorimeter
1181      if(C && (CAL2||CAL1)) {      if(C && (CAL2||CAL1)) {
1182          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));          if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2"));
1183          else    C->SetBranchStatus("CaloLevel2",0,found);  //      else    C->SetBranchStatus("CaloLevel2",0,found);
1184          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;          if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl;
1185          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));          if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1"));
1186          else    C->SetBranchStatus("CaloLevel1",0,found);  //      else    C->SetBranchStatus("CaloLevel1",0,found);
1187          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;          if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl;
1188          if(!Trout)Trout=C;          if(!Trout)Trout=C;
1189          else Trout->AddFriend("Calorimeter");          else Trout->AddFriend("Calorimeter");
# Line 1165  TChain *PamLevel2::GetPamTree(TList *fl, Line 1244  TChain *PamLevel2::GetPamTree(TList *fl,
1244      }else{      }else{
1245          cout << "OrbitalInfo  : missing tree"<<endl;          cout << "OrbitalInfo  : missing tree"<<endl;
1246      };      };
1247    
1248        // Selection List
1249        if(L && SELLI==1) {
1250            cout<<">>> Found selection-list <<<"<<endl;
1251            L->SetBranchAddress("RunEntry",&irun);
1252            cout << "SelectionList: set branch address RunEntry"<<endl;
1253            L->SetBranchAddress("EventEntry",&irunentry);
1254            cout << "SelectionList: set branch address EventEntry"<<endl;
1255            sel_tree = L;
1256    //      if(!Trout)Trout=O;
1257    //      else Trout->AddFriend("SelectionList");
1258        }else{
1259    //      cout << "SelectionList  : missing tree"<<endl;
1260            if(L)L->Delete();
1261        };
1262            
1263  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;  //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl;
1264    
1265            pam_tree = Trout;
1266  //     // Tracker  
 //     if(TRK2||TRK1||TRKh){  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker");  
 //     }  
 //     // Calorimeter  
 //     if(CAL2||CAL1) {          
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter");  
 //     };  
 //     // ToF      
 //     if(TOF) {  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo");  
 //     };  
       
 //    cout<<endl<<" Number of entries: "<<Tout->GetEntries()<<endl<<endl;  
       
 //    if( Tout->GetEntries() )PamLevel2::SetBranchAddress( Tout );  
       
1267      return Trout;      return Trout;
1268  }  }
1269    
# Line 1295  void PamLevel2::SetBranchAddress(TTree * Line 1345  void PamLevel2::SetBranchAddress(TTree *
1345          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1346          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1347      };      };
1348        // SelectionList
1349        if(SELLI==1) {
1350            t->SetBranchAddress("RunEntry", &irun);
1351            cout << "SelectionList: set branch address RunEntry"<<endl;
1352            t->SetBranchAddress("EventEntry", &irunentry);
1353            cout << "SelectionList: set branch address EventEntry"<<endl;
1354        };
1355            
1356  }  }
1357  /**  /**
# Line 1368  void PamLevel2::SetBranchAddress(TChain Line 1425  void PamLevel2::SetBranchAddress(TChain
1425          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));          t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo"));
1426          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;          cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl;
1427      };      };
1428        // SelectionList
1429        if(SELLI==1) {
1430            t->SetBranchAddress("RunEntry", &irun);
1431            cout << "SelectionList: set branch address RunEntry"<<endl;
1432            t->SetBranchAddress("EventEntry", &irunentry);
1433            cout << "SelectionList: set branch address EventEntry"<<endl;
1434        };
1435            
1436  }  }
1437    
# Line 1395  TChain *PamLevel2::GetRunTree(TList *fl) Line 1459  TChain *PamLevel2::GetRunTree(TList *fl)
1459              R->Add(name);              R->Add(name);
1460          };          };
1461      }      }
1462    
1463        if(R->GetNtrees()){
1464            
1465      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1466      cout << "Run         : set branch address RunInfo"<<endl;          cout << "Run         : set branch address RunInfo"<<endl;
1467      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1468      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1469            }else{
1470            delete R;
1471            R=0;
1472        }
1473    
1474        run_tree = R;
1475    
1476      return R;      return R;
1477            
1478  }  }
# Line 1415  TChain *PamLevel2::GetRunTree(TList *fl) Line 1487  TChain *PamLevel2::GetRunTree(TList *fl)
1487   */   */
1488  TTree *PamLevel2::GetRunTree(TFile *f){  TTree *PamLevel2::GetRunTree(TFile *f){
1489    
1490        cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl;
1491    
1492      TTree *R = (TTree*)f->Get("Run");      TTree *R = (TTree*)f->Get("Run");
1493            
1494      R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));      if(R){
1495      cout << "Run         : set branch address RunInfo"<<endl;          R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo"));
1496      R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano          cout << "Run         : set branch address RunInfo"<<endl;
1497      cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano          R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano
1498                cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano
1499        }
1500      return R;      return R;
1501            
1502  }  }
# Line 1437  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 1511  Bool_t PamLevel2::UpdateRunInfo(TChain *
1511    //    //
1512    if ( run->GetEntries() <= 0 ) return(false);    if ( run->GetEntries() <= 0 ) return(false);
1513    //    //
1514      
1515    Int_t oldrun = irun;    Int_t oldrun = irun;
1516    if ( irun < 0 ){    // --------------------------------------
1517      irun = 0;    // if it is a full file (not preselected)
1518      run->GetEntry(0);    // --------------------------------------
1519      runfirstentry = 0ULL;    if(SELLI==0){
1520      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;        if ( irun < 0 ){
1521    };            irun = 0;
1522    while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){            run->GetEntry(0);
1523      //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));            runfirstentry = 0ULL;
1524      irun++;            runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS) - 1ULL;
1525      run->GetEntry(irun);        };
1526      runfirstentry = runlastentry+1ULL;        while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
1527      runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);            //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
1528              irun++;
1529              run->GetEntry(irun);
1530              runfirstentry = runlastentry+1ULL;
1531              runlastentry += (ULong64_t)(this->GetRunInfo()->NEVENTS);
1532          };
1533          //
1534          if ( irun == oldrun || irun >= run->GetEntries() ) return(false);
1535          //
1536          //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);
1537          //
1538          return(true);    
1539    };    };
1540    //    // ----------------------------------------------------
1541    if ( irun == oldrun || irun >= run->GetEntries() ) return(false);    // if it is a preselected file (there is SelectionList)
1542    //    // NBNB - the event tree MUST be read first
1543    //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry);    // ----------------------------------------------------
1544    //    if(SELLI==1){      
1545    return(true);            sel_tree->GetEntry(iev);
1546          if(irun != oldrun){
1547              run->GetEntry(irun);
1548              return true;
1549          }
1550          return false;
1551      }
1552    
1553      return false;
1554    //    //
1555  };  };
1556  /**  /**
# Line 1479  Bool_t PamLevel2::UpdateRunInfo(TTree *r Line 1573  Bool_t PamLevel2::UpdateRunInfo(TTree *r
1573  void PamLevel2::SetWhichTrees(TString detlist){  void PamLevel2::SetWhichTrees(TString detlist){
1574                    
1575      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){      if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){
1576            CAL0 = false;
1577          CAL1 = true;          CAL1 = true;
1578          CAL2 = true;          CAL2 = true;
1579          TRK2 = true;          TRK2 = true;
1580          TRK1 = false;          TRK1 = false;
1581          TRKh = false;          TRKh = false;
1582            TRK0 = false;
1583          TRG = true;          TRG = true;
1584          TOF = true;          TOF = true;
1585            TOF0 = false;
1586          S4  = true;          S4  = true;
1587          ND  = true;          ND  = true;
1588          AC  = true;          AC  = true;
1589          ORB = true;          ORB = true;
1590      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){      }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){
1591            CAL0 = false;
1592          CAL1 = false;          CAL1 = false;
1593          CAL2 = false;          CAL2 = false;
1594          TRK2 = false;          TRK2 = false;
1595          TRK1 = false;          TRK1 = false;
1596          TRKh = false;          TRKh = false;
1597            TRK0 = false;
1598          TRG = false;          TRG = false;
1599          TOF = false;          TOF = false;
1600            TOF0 = false;
1601          S4  = false;          S4  = false;
1602          ND  = false;          ND  = false;
1603          AC  = false;          AC  = false;
# Line 1509  void PamLevel2::SetWhichTrees(TString de Line 1609  void PamLevel2::SetWhichTrees(TString de
1609          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;          if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false;
1610          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;          if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true;
1611      };      };
1612    
1613        if( detlist.Contains("CAL0", TString::kIgnoreCase) ){
1614            if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false;
1615            if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true;
1616        };
1617                    
1618      if( detlist.Contains("CAL2", TString::kIgnoreCase)){      if( detlist.Contains("CAL2", TString::kIgnoreCase)){
1619          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;          if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false;
# Line 1521  void PamLevel2::SetWhichTrees(TString de Line 1626  void PamLevel2::SetWhichTrees(TString de
1626          CAL1=false;          CAL1=false;
1627      }      }
1628  //  -------------------------------------------------------------------------  //  -------------------------------------------------------------------------
1629        if( detlist.Contains("TRK0", TString::kIgnoreCase) ){
1630            if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false;
1631            if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true;
1632        };
1633    
1634      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){      if( detlist.Contains("TRK1", TString::kIgnoreCase) ){
1635          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;          if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false;
1636          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;          if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true;
# Line 1549  void PamLevel2::SetWhichTrees(TString de Line 1659  void PamLevel2::SetWhichTrees(TString de
1659            
1660      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;      if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false;
1661      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;      else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true;
1662    
1663        if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false;
1664        else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true;
1665            
1666      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;      if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false;
1667      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;      else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true;
# Line 1583  void PamLevel2::SetWhichTrees(TString de Line 1696  void PamLevel2::SetWhichTrees(TString de
1696   * Set tree/branch detector flags from the content of a tree   * Set tree/branch detector flags from the content of a tree
1697   */   */
1698  void  PamLevel2::GetWhichTrees(TFile* f){  void  PamLevel2::GetWhichTrees(TFile* f){
1699                
1700    
1701    
1702        cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl;
1703      // -----------      // -----------
1704      // reset flags      // reset flags
1705      // -----------      // -----------
# Line 1755  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1871  Bool_t  PamLevel2::CheckLevel2File(TStri
1871            
1872      Bool_t RUN__ok    = false;      Bool_t RUN__ok    = false;
1873            
1874            Bool_t SELLI__ok  = false;
1875    
1876      cout << "Checking file: "<<name<<endl;      cout << "Checking file: "<<name<<endl;
1877      TFile *f = new TFile(name.Data());      TFile *f = new TFile(name.Data());
# Line 1772  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1888  Bool_t  PamLevel2::CheckLevel2File(TStri
1888    
1889      while( (key = (TKey*)next()) ){      while( (key = (TKey*)next()) ){
1890                    
1891    //      cout << key->GetName() << endl;
1892  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;  //      cout << key->GetName() << ""<<key->GetClassName()<<endl;
1893  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;  //              cout << " Get tree: " << f->Get(key->GetName())<<endl;
1894  //      nev_previous = nev;  //      nev_previous = nev;
# Line 1782  Bool_t  PamLevel2::CheckLevel2File(TStri Line 1899  Bool_t  PamLevel2::CheckLevel2File(TStri
1899  //          return false;  //          return false;
1900  //      };  //      };
1901    
1902    
1903          if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;                if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true;      
1904    
1905          //=========================================================              //=========================================================    
1906            if( !strcmp(key->GetName(),"SelectionList"    ) ){
1907                SELLI__ok = true;
1908                if(SELLI==1){
1909                    Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries();
1910                    if( nev && nevt!=nev){
1911                        cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl;
1912                        return false;
1913                    }
1914                    nev=nevt;
1915                }
1916            }
1917    
1918            //=========================================================    
1919          if( !strcmp(key->GetName(),"Trigger"    ) ){          if( !strcmp(key->GetName(),"Trigger"    ) ){
1920              TRG__ok = true;              TRG__ok = true;
1921              if(TRG){              if(TRG){
# Line 1896  Bool_t  PamLevel2::CheckLevel2File(TStri Line 2027  Bool_t  PamLevel2::CheckLevel2File(TStri
2027          };                };      
2028    
2029      };      };
2030    
2031        if( SELLI==-1 )SELLI = (Int_t)SELLI__ok;
2032        if( SELLI==0 && SELLI__ok ){
2033            cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl;
2034            return false;  
2035        }
2036        if( SELLI==1 && !SELLI__ok ){
2037            cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl;
2038            return false;
2039        }
2040            
2041    //    cout << "SELLI "<<SELLI<<endl;
2042    
2043  //     cout<< "CheckLevel2File(TString): detector list --> ";  //     cout<< "CheckLevel2File(TString): detector list --> ";
2044  //     if(TRK1__ok)cout<<"TRK1 ";  //     if(TRK1__ok)cout<<"TRK1 ";
2045  //     if(TRK2__ok)cout<<"TRK2 ";  //     if(TRK2__ok)cout<<"TRK2 ";
# Line 2005  void PamLevel2::CreateCloneTrees0( TChai Line 2148  void PamLevel2::CreateCloneTrees0( TChai
2148      cout << "Create clones of PAMELA trees "<<endl;      cout << "Create clones of PAMELA trees "<<endl;
2149            
2150      Int_t i=0;      Int_t i=0;
2151      tree_clone[i] = fChain->GetTree()->CloneTree(0);      pam_tree_clone[i] = fChain->GetTree()->CloneTree(0);
2152      TString name =  tree_clone[i]->GetName();      TString name =  pam_tree_clone[i]->GetName();
2153      name.Append("_clone");      name.Append("_clone");
2154  //    tree_clone[i]->SetName(name.Data());  //    pam_tree_clone[i]->SetName(name.Data());
2155      cout << tree_clone[i]->GetName() <<endl;      cout << pam_tree_clone[i]->GetName() <<endl;
2156      i++;      i++;
2157    
2158      TList *li = fChain->GetListOfFriends();      TList *li = fChain->GetListOfFriends();
# Line 2019  void PamLevel2::CreateCloneTrees0( TChai Line 2162  void PamLevel2::CreateCloneTrees0( TChai
2162      while( (T_friend = (TFriendElement*)next()) ){      while( (T_friend = (TFriendElement*)next()) ){
2163  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;
2164  //      cout<<T_friend->GetTree()->GetName()<< endl;  //      cout<<T_friend->GetTree()->GetName()<< endl;
2165          tree_clone[i] = T_friend->GetTree()->CloneTree(0);          pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0);
2166          tree_clone[i]->SetAutoSave(1000000);          pam_tree_clone[i]->SetAutoSave(1000000);
2167          name =  tree_clone[i]->GetName();          name =  pam_tree_clone[i]->GetName();
2168          name.Append("_clone");          name.Append("_clone");
2169  //      tree_clone[i]->SetName(name.Data());  //      pam_tree_clone[i]->SetName(name.Data());
2170          cout << tree_clone[i]->GetName() << endl;          cout << pam_tree_clone[i]->GetName() << endl;
2171          i++;          i++;
2172      }      }
2173            
# Line 2044  void PamLevel2::CreateCloneTrees(TFile * Line 2187  void PamLevel2::CreateCloneTrees(TFile *
2187      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2188      cout << "Create new PAMELA trees "<<endl;      cout << "Create new PAMELA trees "<<endl;
2189                    
     Int_t i=0;  
2190    
2191        run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table ");
2192        run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo"));
2193        cout << "Run          : branch RunInfo"<<endl;
2194        run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo"));
2195        cout << "Run          : branch SoftInfo"<<endl;
2196                
2197    
2198    
2199        sel_tree_clone = new TTree("SelectionList","List of selected events ");
2200        sel_tree_clone->Branch("RunEntry",&irun,"runentry/I");
2201        sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/I");
2202        
2203    
2204        Int_t i=0;
2205      if(TRK1||TRK2||TRKh){      if(TRK1||TRK2||TRKh){
2206          tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");              pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data ");
2207          if(TRK1) {          if(TRK1) {
2208              tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));              pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1"));
2209              tree_clone[i]->BranchRef();              pam_tree_clone[i]->BranchRef();
2210              cout << "Tracker      : branch TrkLevel1"<<endl;              cout << "Tracker      : branch TrkLevel1"<<endl;
2211          };          };
2212          if(TRK2) {          if(TRK2) {
2213              tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));              pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2"));
2214              cout << "Tracker      : branch TrkLevel2"<<endl;                      cout << "Tracker      : branch TrkLevel2"<<endl;        
2215          };          };
2216          if(TRKh) {          if(TRKh) {
2217              tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));              pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough"));
2218              cout << "Tracker      : branch TrkHough"<<endl;              cout << "Tracker      : branch TrkHough"<<endl;
2219          };          };
2220          i++;          i++;
# Line 2066  void PamLevel2::CreateCloneTrees(TFile * Line 2222  void PamLevel2::CreateCloneTrees(TFile *
2222    
2223      // Calorimeter      // Calorimeter
2224      if(CAL1||CAL2){      if(CAL1||CAL2){
2225          tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");              pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data ");
2226          if(CAL1) {          if(CAL1) {
2227              tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));              pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1"));
2228              cout << "Calorimeter  : branch CaloLevel1"<<endl;              cout << "Calorimeter  : branch CaloLevel1"<<endl;
2229          };          };
2230          if(CAL2) {          if(CAL2) {
2231              tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));              pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2"));
2232              cout << "Calorimeter  : branch CaloLevel2"<<endl;              cout << "Calorimeter  : branch CaloLevel2"<<endl;
2233          };          };
2234          i++;          i++;
# Line 2080  void PamLevel2::CreateCloneTrees(TFile * Line 2236  void PamLevel2::CreateCloneTrees(TFile *
2236    
2237      // ToF          // ToF    
2238      if(TOF) {      if(TOF) {
2239          tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");              pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data ");
2240          tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));          pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2"));
2241          cout << "ToF          : branch ToFLevel2"<<endl;          cout << "ToF          : branch ToFLevel2"<<endl;
2242          i++;          i++;
2243      };      };
2244      // Trigger      // Trigger
2245      if(TRG) {      if(TRG) {
2246          tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");              pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data ");
2247          tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));          pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2"));
2248          cout << "Trigger      : branch TrigLevel2"<<endl;          cout << "Trigger      : branch TrigLevel2"<<endl;
2249          i++;          i++;
2250      };      };
2251      // S4      // S4
2252      if(S4) {      if(S4) {
2253          tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");                pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data ");  
2254          tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));          pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2"));
2255          cout << "S4           : branch S4Level2"<<endl;          cout << "S4           : branch S4Level2"<<endl;
2256          i++;          i++;
2257      };      };
2258      // Neutron Detector      // Neutron Detector
2259      if(ND) {      if(ND) {
2260          tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");            pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data ");      
2261          tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));          pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2"));
2262          cout << "NeutronD     : branch NDLevel2"<<endl;          cout << "NeutronD     : branch NDLevel2"<<endl;
2263          i++;          i++;
2264      };      };
2265      // Anticounters      // Anticounters
2266      if(AC) {      if(AC) {
2267          tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");              pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data ");        
2268          tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));          pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2"));
2269          cout << "Anticounter  : branch AcLevel2"<<endl;          cout << "Anticounter  : branch AcLevel2"<<endl;
2270          i++;          i++;
2271      };      };
2272      // OrbitalInfo      // OrbitalInfo
2273      if(ORB) {      if(ORB) {
2274          tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");                pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  ");  
2275          tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));          pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo"));
2276          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;          cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;
2277          i++;          i++;
2278      };      };
# Line 2131  void PamLevel2::CreateCloneTrees(TFile * Line 2287  void PamLevel2::CreateCloneTrees(TFile *
2287   */   */
2288  //void PamLevel2::FillNewPamTree(TTree *T){  //void PamLevel2::FillNewPamTree(TTree *T){
2289  void PamLevel2::FillCloneTrees(){  void PamLevel2::FillCloneTrees(){
2290                
2291      for(Int_t i=0; i<8; i++){  //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl;
2292          if(tree_clone[i])tree_clone[i]->Fill();      for(Int_t i=0; i<NCLONES; i++){
2293            if(pam_tree_clone[i])pam_tree_clone[i]->Fill();
2294        }
2295        if(sel_tree_clone)sel_tree_clone->Fill();    
2296    //    if( irunentry == 0 || run_tree_clone->GetEntries()==0 )run_tree_clone->Fill();
2297        Int_t nstoredruns = run_tree_clone->GetEntries();
2298        if( irun ==  nstoredruns )run_tree_clone->Fill();
2299        else if( irun > nstoredruns || irun < nstoredruns-1){
2300            cout << " PamLevel2::FillCloneTrees() -- ERROR -- current run "<< irun <<" stored runs "<< nstoredruns <<endl;
2301      }      }
2302  }  }
2303    
2304    
2305  TTree* PamLevel2::GetCloneTree(TString name){  TTree* PamLevel2::GetCloneTree(TString name){
2306    
2307      for(Int_t i=0; i<8; i++){        for(Int_t i=0; i<NCLONES; i++){    
2308          if(tree_clone[i]){          if(pam_tree_clone[i]){
2309              TString na = tree_clone[i]->GetName();              TString na = pam_tree_clone[i]->GetName();
2310              if(!name.CompareTo(na))return tree_clone[i];              if(!name.CompareTo(na))return pam_tree_clone[i];
2311          };          };
2312      }      }
2313        if(run_tree_clone){
2314            TString na = run_tree_clone->GetName();
2315            if(!name.CompareTo(na))return run_tree_clone;
2316        }
2317        if(sel_tree_clone){
2318            TString na = sel_tree_clone->GetName();
2319            if(!name.CompareTo(na))return sel_tree_clone;
2320        }
2321      return NULL;      return NULL;
2322    
2323  }  }
2324  void PamLevel2::WriteCloneTrees(){  void PamLevel2::WriteCloneTrees(){
2325      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
2326      cout << "Write clones of PAMELA trees "<<endl;      cout << "Write clones of PAMELA trees "<<endl;
2327      for(Int_t i=0; i<8; i++){        cout << run_tree_clone->GetName()<<endl;    
2328          if(tree_clone[i]){      run_tree_clone->Write();
2329              cout << tree_clone[i]->GetName()<<endl;      cout << sel_tree_clone->GetName()<<endl;    
2330              tree_clone[i]->Write();      sel_tree_clone->Write();
2331        for(Int_t i=0; i<NCLONES; i++){    
2332            if(pam_tree_clone[i]){
2333                cout << pam_tree_clone[i]->GetName()<<endl;
2334                pam_tree_clone[i]->Write();
2335          };          };
2336      }      }
2337      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;      cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;
# Line 2163  void PamLevel2::WriteCloneTrees(){ Line 2339  void PamLevel2::WriteCloneTrees(){
2339  }  }
2340    
2341  /**  /**
2342   * Create a new (empty) Pamela trees   * Method to get both level2-trees entry and corresponding run entry.
2343   */   */
 // TTree* PamLevel2::GetNewPamTree(){  
2344    
 //     if(tree_clone)return tree_clone;  
2345    
2346  //     TTree *Tout = 0;  Int_t PamLevel2::GetEntry(Int_t iee){
       
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
 //     cout << "Create new PAMELA trees "<<endl;  
2347            
2348            if(!pam_tree){
2349  //     if(TRK1||TRK2||TRKh){          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loeaded"<<endl;
2350  //      TTree *T = new TTree("Tracker_clone","PAMELA tracker level2 data ");              return 0;
2351  //      if(TRK1) {      }
2352  //          trk1_clone = new TrkLevel1();      if(!run_tree ){
2353  //          T->Branch("TrkLevel1","TrkLevel1", &trk1_clone);          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl;
2354  //          T->BranchRef();          return 0;
2355  //          cout << "Tracker      : branch TrkLevel1"<<endl;      }
 //      };  
 //      if(TRK2) {  
 //          trk2_clone = new TrkLevel2();  
 //          T->Branch("TrkLevel2", "TrkLevel2",&trk2_clone);  
 //          cout << "Tracker      : branch TrkLevel2"<<endl;          
 //      };  
 //      if(TRKh) {  
 //          trkh_clone = new TrkHough();  
 //          T->Branch("TrkHough","TrkHough", &trkh_clone);  
 //          cout << "Tracker      : branch TrkHough"<<endl;  
 //      };  
 //      if(!Tout)Tout=T;  
 //      else Tout->AddFriend("Tracker_clone");  
 //     }  
   
 //     // Calorimeter  
 //     if(CAL1||CAL2){  
 //      TTree *C = new TTree("Calorimeter_clone","PAMELA calorimeter level2 data ");      
 //      if(CAL1) {  
 //          calo1_clone = new CaloLevel1();  
 //          C->Branch("CaloLevel1", "CaloLevel1", &calo1_clone);  
 //          cout << "Calorimeter  : branch CaloLevel1"<<endl;  
 //      };  
 //      if(CAL2) {  
 //          calo2_clone = new CaloLevel2();  
 //          C->Branch("CaloLevel2","CaloLevel2", &calo2_clone);  
 //          cout << "Calorimeter  : branch CaloLevel2"<<endl;  
 //      };  
 //      if(!Tout)Tout=C;  
 //      else Tout->AddFriend("Calorimeter_clone");  
 //     }      
   
 //     // ToF      
 //     if(TOF) {  
 //      TTree *O = new TTree("ToF_clone","PAMELA ToF level2 data ");      
 //      tof_clone = new ToFLevel2();  
 //      O->Branch("ToFLevel2","ToFLevel2", &tof_clone);  
 //      cout << "ToF          : branch ToFLevel2"<<endl;  
 //      if(!Tout)Tout=O;  
 //      else Tout->AddFriend("ToF_clone");  
 //     };  
 //     // Trigger  
 //     if(TRG) {  
 //      TTree *R = new TTree("Trigger_clone","PAMELA trigger level2 data ");      
 //      trig_clone = new TrigLevel2();  
 //      R->Branch("TrigLevel2","TrigLevel2", &trig_clone);  
 //      cout << "Trigger      : branch TrigLevel2"<<endl;  
 //      if(!Tout)Tout=R;  
 //      else Tout->AddFriend("Trigger_clone");  
 //     };  
 //     // S4  
 //     if(S4) {  
 //      TTree *S = new TTree("S4_clone","PAMELA S4 level2 data ");        
 //      s4_clone = new S4Level2();  
 //      S->Branch("S4Level2","S4Level2", &s4_clone);  
 //      cout << "S4           : branch S4Level2"<<endl;  
 //      if(!Tout)Tout=S;  
 //      else Tout->AddFriend("S4_clone");  
 //     };  
 //     // Neutron Detector  
 //     if(ND) {  
 //      TTree *N = new TTree("NeutronD_clone","PAMELA neutron detector level2 data ");    
 //      nd_clone = new NDLevel2();  
 //      N->Branch("NDLevel2","NDLevel2", &nd_clone);  
 //      cout << "NeutronD     : branch NDLevel2"<<endl;  
 //      if(!Tout)Tout=N;  
 //      else Tout->AddFriend("NeutronD_clone");  
 //     };  
 //     // Anticounters  
 //     if(AC) {  
 //      TTree *A = new TTree("Anticounter_clone","PAMELA anticounter detector level2 data ");    
 //      ac_clone = new AcLevel2();  
 //      A->Branch("AcLevel2","AcLevel2", &ac_clone);  
 //      cout << "Anticounter  : branch AcLevel2"<<endl;  
 //      if(!Tout)Tout=A;  
 //      else Tout->AddFriend("Anticounter_clone");  
 //     };  
 //     // OrbitalInfo  
 //     if(ORB) {  
 //      TTree *B = new TTree("OrbitalInfo_clone","PAMELA oribital info  ");      
 //      orb_clone = new OrbitalInfo();  
 //      B->Branch("OrbitalInfo","OrbitalInfo", &orb_clone);  
 //      cout << "OrbitalInfo  : branch OrbitalInfo"<<endl;  
 //      if(!Tout)Tout=B;  
 //      else Tout->AddFriend("OrbitalInfo_clone");  
 //     };  
 //     cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl;  
2356    
2357  //     tree_clone = Tout;      Int_t ii=0;
2358  //     tree_clone->SetDirectory(0);      //-------------------------------
2359        ii = iee;
2360        if( !pam_tree->GetEntry(ii) ) return 0;
2361        //-------------------------------
2362        ii = iee;
2363        UpdateRunInfo(run_tree,ii);
2364        if(SELLI==0)irunentry = iee-runfirstentry;
2365    
2366  //     return Tout;  //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl;
2367  // }  
2368  // /**      if( TRK0 || CAL0 || TOF0 )GetYodaEntry( );
2369  //  * Fill a tree (created with GetNewPamTree)  
2370  //  *      return 1;
 //  */  
 // //void PamLevel2::FillNewPamTree(TTree *T){  
 // void PamLevel2::FillNewPamTree(){  
           
2371    
2372  //     if(trk1_clone)  *trk1_clone = *trk1_obj;  }
2373  //     if(trk2_clone){  
2374  //      trk2_clone->Clear();  /**
2375  //      trk2_obj->Copy(*trk2_clone);   * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2376  // //   *trk2_clone = *trk2_obj;   * Given the run ID (...), if needed it query the DB and load the proper file.
2377  //     }   * @return Pointer to the tree
2378  //     if(trkh_clone)  *trkh_clone = *trkh_obj;   */
 //     if(calo1_clone){  
 // //   *calo1_clone = *calo1_obj;  
 //      calo1_clone->Clear();  
 //      calo1_obj->Copy(*calo1_clone);  
 //     }  
 //     if(calo2_clone){  
 // //   *calo2_clone = *calo2_obj;  
 //      calo2_clone->Clear();  
 //      calo2_obj->Copy(*calo2_clone);  
 //     }  
 //     if(tof_clone)   *tof_clone  = *tof_obj;  
 //     if(trig_clone)  *trig_clone = *trig_obj;  
 //     if(s4_clone)    *s4_clone   = *s4_obj;  
 //     if(nd_clone)    *nd_clone   = *nd_obj;  
 //     if(ac_clone)    *ac_clone   = *ac_obj;  
 //     if(orb_clone)   *orb_clone  = *orb_obj;  
   
 //     TTree *T = tree_clone;  
   
 //     T->Fill(); //fill main tree  
 // //    cout<<T->IsA()->GetName()<<" "<<T->GetName()<<endl;  
 //     TList *li = T->GetListOfFriends();  
 //     TIter next(li);  
 //     TFriendElement* T_friend=0;  
 //     while( (T_friend = (TFriendElement*)next()) ){  
 // //   cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl;  
 //      T_friend->GetTree()->Fill();//fill friends  
 //     }  
2379    
2380  // }  
2381    TTree* PamLevel2::GetYodaTree( ){
2382        
2383    //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl;
2384        //===================================
2385        // check if iroot has changed
2386        //===================================
2387        if( irun<0 ){
2388            cout << "PamLevel2::GetYodaTree() -- ERROR "<<endl;
2389            cout << "In order to use this method you have to load the RunInfo tree "<<endl;
2390            cout << "with the method TChain* PamLevel2::GetRunTree(TString, TString)"<<endl;
2391    //      cout << " - read the event with PamLevel2::GetEntry(Int_t)"<<endl;
2392            return NULL;
2393        }    
2394        Int_t irootnew = run_obj->ID_ROOT_L0;
2395    //    cout << "iroot    "<<iroot<<endl;
2396    //    cout << "irootnew "<<irootnew<<endl;
2397    
2398        //===================================
2399        // load the level0 file
2400        // (if not already loaded)
2401        //===================================
2402        if( iroot != irootnew || !l0_tree){
2403            iroot = irootnew;
2404            //===================================
2405            // open the DB connection
2406            // (if not already opened)
2407            //===================================
2408            if(!dbc || (dbc && !dbc->IsConnected())){
2409                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2410                cout<<"Connecting to DB"<<endl;
2411                cout<<"HOST "<<host<<endl;
2412                cout<<"USER "<<user<<endl;
2413                cout<<"PSW  "<<psw<<endl;
2414                dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
2415                if( !dbc )return NULL;
2416                if( !dbc->IsConnected() )return NULL;    
2417    //          cout<<"...done"<<endl;
2418                cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
2419            }else{
2420    //          cout<<"DB already connected"<<endl;
2421            }
2422            GL_ROOT glroot = GL_ROOT();
2423            if( glroot.Query_GL_ROOT(iroot,dbc) )return NULL;
2424            TString filename = glroot.PATH + glroot.NAME;
2425            if(l0_file){
2426                l0_file->Close();
2427                l0_file->Delete();
2428            }
2429            cout << "Opening LEVEL0 file: "<< filename << endl;
2430            FileStat_t t;
2431            if( gSystem->GetPathInfo(filename.Data(),t) ){
2432                cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl;
2433                return NULL;
2434            }
2435            l0_file = new TFile(filename);
2436            if( !l0_file )return NULL;
2437            l0_tree = (TTree*)l0_file->Get("Physics");
2438            if(!h0_obj)h0_obj = new EventHeader();
2439            l0_tree->SetBranchAddress("Header" ,&h0_obj);
2440            //---------------------------------------------------
2441            // TRACKER:
2442            if(TRK0){
2443                if(!trk0_obj){
2444                    trk0_obj = new TrkLevel0();
2445                    trk0_obj->Set();
2446                };
2447                l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent());
2448                TrkParams::SetCalib(run_obj,dbc);
2449            }
2450            //---------------------------------------------------
2451            // CALORIMETER:
2452            if(CAL0){
2453                cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl;
2454            }
2455            //---------------------------------------------------
2456            // TOF:
2457            if(TOF0){
2458                cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl;
2459            }
2460    
2461        };
2462    
2463        return l0_tree;
2464    
2465    }
2466    
2467    /**
2468     * Method to retrieve the level0 tree (YODA tree) that contains the current event.
2469     */
2470    Int_t PamLevel2::GetYodaEntry(){
2471    
2472    //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl;
2473        if(!GetYodaTree())return 0;
2474        
2475        //  ---------------------------------
2476        //  if file is NOT a preselected file
2477        //  ---------------------------------
2478        Int_t quellagiusta = irunentry + run_obj->EV_FROM;
2479        //  ------------------------------------------
2480        //  otherwise read the "preselected-list" tree
2481        //  ------------------------------------------
2482    
2483    //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl;
2484        return GetYodaTree()->GetEntry(quellagiusta);
2485        
2486        return 1;
2487        
2488    }

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.23